From 3350279e58cb5810e74e6999fcdb02f22cc4e1d9 Mon Sep 17 00:00:00 2001 From: Jeff Tung <100387939+jtung-apple@users.noreply.github.com> Date: Mon, 2 Oct 2023 14:57:35 -0700 Subject: [PATCH] [Darwin] MTRDeviceTests test017 - fix resubscription expectation (#29458) * [Darwin] MTRDeviceTests test017 - fix resubscription expectation * Update src/app/InteractionModelEngine.h Co-authored-by: Boris Zbarsky --------- Co-authored-by: Boris Zbarsky --- src/app/InteractionModelEngine.h | 2 +- .../Framework/CHIPTests/MTRDeviceTests.m | 19 +++++++++++-------- .../CHIPTests/TestHelpers/MTRTestKeys.m | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/app/InteractionModelEngine.h b/src/app/InteractionModelEngine.h index e2e42cb0c19b66..0ecf3f6c6b1ec0 100644 --- a/src/app/InteractionModelEngine.h +++ b/src/app/InteractionModelEngine.h @@ -679,7 +679,7 @@ CHIP_ERROR ReadSingleClusterData(const Access::SubjectDescriptor & aSubjectDescr /** * Check whether concrete attribute path is an "existent attribute path" in spec terms. * @param[in] aPath The concrete path of the data being read. - * @retval boolean + * @retval boolean true if the concrete attribute path indicates an attribute that exists on the node. */ bool ConcreteAttributePathExists(const ConcreteAttributePath & aPath); diff --git a/src/darwin/Framework/CHIPTests/MTRDeviceTests.m b/src/darwin/Framework/CHIPTests/MTRDeviceTests.m index 5db526a0394229..618a2f2648e571 100644 --- a/src/darwin/Framework/CHIPTests/MTRDeviceTests.m +++ b/src/darwin/Framework/CHIPTests/MTRDeviceTests.m @@ -75,6 +75,9 @@ static void WaitForCommissionee(XCTestExpectation * expectation) #ifdef DEBUG @interface MTRBaseDevice (Test) - (void)failSubscribers:(dispatch_queue_t)queue completion:(void (^)(void))completion; + +// Test function for whitebox testing ++ (id)CHIPEncodeAndDecodeNSObject:(id)object; @end #endif @@ -1558,9 +1561,14 @@ - (void)test017_TestMTRDeviceBasics delegate.onNotReachable = ^() { [subscriptionDroppedExpectation fulfill]; }; - XCTestExpectation * resubscriptionExpectation = [self expectationWithDescription:@"Resubscription has happened"]; + XCTestExpectation * resubscriptionReachableExpectation = + [self expectationWithDescription:@"Resubscription has become reachable"]; delegate.onReachable = ^() { - [resubscriptionExpectation fulfill]; + [resubscriptionReachableExpectation fulfill]; + }; + XCTestExpectation * resubscriptionGotReportsExpectation = [self expectationWithDescription:@"Resubscription got reports"]; + delegate.onReportEnd = ^() { + [resubscriptionGotReportsExpectation fulfill]; }; // reset the onAttributeDataReceived to validate the following resubscribe test @@ -1598,7 +1606,7 @@ - (void)test017_TestMTRDeviceBasics // Check that device resets start time on subscription drop XCTAssertNil(device.estimatedStartTime); - [self waitForExpectations:@[ resubscriptionExpectation ] timeout:60]; + [self waitForExpectations:@[ resubscriptionReachableExpectation, resubscriptionGotReportsExpectation ] timeout:60]; // Now make sure we ignore later tests. Ideally we would just unsubscribe // or remove the delegate, but there's no good way to do that. @@ -2585,11 +2593,6 @@ - (void)test999_TearDown @end -@interface MTRBaseDevice (Test) -// Test function for whitebox testing -+ (id)CHIPEncodeAndDecodeNSObject:(id)object; -@end - @interface MTRDeviceEncoderTests : XCTestCase @end diff --git a/src/darwin/Framework/CHIPTests/TestHelpers/MTRTestKeys.m b/src/darwin/Framework/CHIPTests/TestHelpers/MTRTestKeys.m index 23b602e2e7208c..e6a74f25bdeccf 100644 --- a/src/darwin/Framework/CHIPTests/TestHelpers/MTRTestKeys.m +++ b/src/darwin/Framework/CHIPTests/TestHelpers/MTRTestKeys.m @@ -57,7 +57,7 @@ - (instancetype)init CFErrorRef error = NULL; const NSDictionary * keygenParams = @{ (__bridge NSString *) kSecAttrKeyClass : (__bridge NSString *) kSecAttrKeyClassPrivate, - (__bridge NSString *) kSecAttrKeyType : (__bridge NSNumber *) kSecAttrKeyTypeECSECPrimeRandom, + (__bridge NSString *) kSecAttrKeyType : (__bridge NSString *) kSecAttrKeyTypeECSECPrimeRandom, (__bridge NSString *) kSecAttrKeySizeInBits : @(keySizeInBits), (__bridge NSString *) kSecAttrIsPermanent : @(NO) };