Skip to content

Commit 95bb577

Browse files
Stop using MinInterval = 2 in tests that expect reports within 3 seconds.
We had a bunch of subscription Darwin tests that set a 2-second MinInterval but expected reports within 3 seconds. This seems to have worked because for some reason the 2-second timers fired pretty early (at closer to 1.5 seconds) on the existing runners, but on the new ARM runners it actually fires at 2 seconds, and then we have a very high test timeout rate. The fix is to just use a MinInterval of 0 for the relevant subscriptions. test012_SubscribeKeepingPreviousSubscription turned out to be relying on not getting reports from when it sends the Off command until it sends the followup On command, but now we do in fact send those reports. So we need to wait for them to clear through before we send the On command.
1 parent 3136753 commit 95bb577

File tree

2 files changed

+62
-14
lines changed

2 files changed

+62
-14
lines changed

src/darwin/Framework/CHIPTests/MTRDeviceTests.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ - (void)test011_ReadCachedAttribute
815815
NSLog(@"Subscribing...");
816816
// reportHandler returns TRUE if it got the things it was looking for or if there's an error.
817817
__block BOOL (^reportHandler)(NSArray * _Nullable value, NSError * _Nullable error);
818-
__auto_type * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(2) maxInterval:@(60)];
818+
__auto_type * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(0) maxInterval:@(60)];
819819
params.resubscribeAutomatically = NO;
820820
[device subscribeWithQueue:queue
821821
params:params
@@ -881,7 +881,7 @@ - (void)test011_ReadCachedAttribute
881881
// Add another subscriber of the attribute to verify that attribute cache still works when there are other subscribers.
882882
NSLog(@"New subscription...");
883883
XCTestExpectation * newSubscriptionEstablished = [self expectationWithDescription:@"New subscription established"];
884-
MTRSubscribeParams * newParams = [[MTRSubscribeParams alloc] initWithMinInterval:@(2) maxInterval:@(60)];
884+
MTRSubscribeParams * newParams = [[MTRSubscribeParams alloc] initWithMinInterval:@(0) maxInterval:@(60)];
885885
newParams.replaceExistingSubscriptions = NO;
886886
newParams.resubscribeAutomatically = NO;
887887
[cluster subscribeAttributeOnOffWithParams:newParams

src/darwin/Framework/CHIPTests/MTRXPCListenerSampleTests.m

+60-12
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ - (void)test004_Subscribe
758758
MTRBaseDevice * device = GetConnectedDevice();
759759
dispatch_queue_t queue = dispatch_get_main_queue();
760760

761-
__auto_type * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(2) maxInterval:@(10)];
761+
__auto_type * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(0) maxInterval:@(10)];
762762
[device subscribeToAttributesWithEndpointID:@1
763763
clusterID:@6
764764
attributeID:@0
@@ -958,7 +958,7 @@ - (void)test008_SubscribeFailure
958958
MTRBaseDevice * device = GetConnectedDevice();
959959
dispatch_queue_t queue = dispatch_get_main_queue();
960960

961-
__auto_type * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(2) maxInterval:@(10)];
961+
__auto_type * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(0) maxInterval:@(10)];
962962
params.resubscribeAutomatically = NO;
963963
[device subscribeToAttributesWithEndpointID:@10000
964964
clusterID:@6
@@ -1039,7 +1039,7 @@ - (void)test010_SubscribeWithNoParams
10391039

10401040
// Subscribe
10411041
XCTestExpectation * subscribeExpectation = [self expectationWithDescription:@"subscribe OnOff attribute"];
1042-
__auto_type * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(2) maxInterval:@(10)];
1042+
__auto_type * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(0) maxInterval:@(10)];
10431043
[device subscribeToAttributesWithEndpointID:@1
10441044
clusterID:@6
10451045
attributeID:@0
@@ -1064,7 +1064,7 @@ - (void)test010_SubscribeWithNoParams
10641064

10651065
// Setup 2nd subscriber
10661066
subscribeExpectation = [self expectationWithDescription:@"subscribe CurrentLevel attribute"];
1067-
params = [[MTRSubscribeParams alloc] initWithMinInterval:@(2) maxInterval:@(10)];
1067+
params = [[MTRSubscribeParams alloc] initWithMinInterval:@(0) maxInterval:@(10)];
10681068
[device subscribeToAttributesWithEndpointID:@1
10691069
clusterID:@8
10701070
attributeID:@0
@@ -1212,7 +1212,7 @@ - (void)test011_SubscribeWithParams
12121212

12131213
// Subscribe
12141214
XCTestExpectation * subscribeExpectation = [self expectationWithDescription:@"subscribe OnOff attribute"];
1215-
__auto_type * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(2) maxInterval:@(10)];
1215+
__auto_type * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(0) maxInterval:@(10)];
12161216
[device subscribeToAttributesWithEndpointID:@1
12171217
clusterID:@6
12181218
attributeID:@0
@@ -1236,7 +1236,7 @@ - (void)test011_SubscribeWithParams
12361236
[self waitForExpectations:@[ subscribeExpectation ] timeout:kTimeoutInSeconds];
12371237

12381238
// Setup 2nd subscriber
1239-
MTRSubscribeParams * myParams = [[MTRSubscribeParams alloc] initWithMinInterval:@(2) maxInterval:@(10)];
1239+
MTRSubscribeParams * myParams = [[MTRSubscribeParams alloc] initWithMinInterval:@(0) maxInterval:@(10)];
12401240
myParams.replaceExistingSubscriptions = YES;
12411241
subscribeExpectation = [self expectationWithDescription:@"subscribe CurrentLevel attribute"];
12421242
[device subscribeToAttributesWithEndpointID:@1
@@ -1390,10 +1390,31 @@ - (void)test012_SubscribeKeepingPreviousSubscription
13901390

13911391
__block void (^firstReportHandler)(id _Nullable values, NSError * _Nullable error) = nil;
13921392
__block void (^secondReportHandler)(id _Nullable values, NSError * _Nullable error) = nil;
1393+
// Depending on how this test is run (alone or after other tests), we might
1394+
// be either in the "On" or "Off" state when we start. Track that, so we
1395+
// can ensure we're in the "Off" state correctly later.
1396+
__block BOOL initialOnOffState;
1397+
1398+
XCTestExpectation * initialOnOffReportExpectation = [self expectationWithDescription:@"initial OnOff report expectation"];
1399+
firstReportHandler = ^(id _Nullable values, NSError * _Nullable error) {
1400+
XCTAssertNil(error);
1401+
1402+
XCTAssertTrue([values isKindOfClass:[NSArray class]]);
1403+
NSDictionary * result = values[0];
1404+
MTRAttributePath * path = result[@"attributePath"];
1405+
XCTAssertEqual([path.endpoint unsignedIntegerValue], 1);
1406+
XCTAssertEqual([path.cluster unsignedIntegerValue], 6);
1407+
XCTAssertEqual([path.attribute unsignedIntegerValue], 0);
1408+
XCTAssertTrue([result[@"data"] isKindOfClass:[NSDictionary class]]);
1409+
XCTAssertTrue([result[@"data"][@"type"] isEqualToString:@"Boolean"]);
1410+
initialOnOffState = [result[@"data"][@"value"] boolValue];
1411+
1412+
[initialOnOffReportExpectation fulfill];
1413+
};
13931414

13941415
// Subscribe
13951416
XCTestExpectation * subscribeExpectation = [self expectationWithDescription:@"subscribe OnOff attribute"];
1396-
__auto_type * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(2) maxInterval:@(10)];
1417+
__auto_type * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(0) maxInterval:@(10)];
13971418
[device subscribeToAttributesWithEndpointID:@1
13981419
clusterID:@6
13991420
attributeID:@0
@@ -1414,11 +1435,11 @@ - (void)test012_SubscribeKeepingPreviousSubscription
14141435
[subscribeExpectation fulfill];
14151436
}];
14161437

1417-
[self waitForExpectations:@[ subscribeExpectation ] timeout:kTimeoutInSeconds];
1438+
[self waitForExpectations:@[ subscribeExpectation, initialOnOffReportExpectation ] timeout:kTimeoutInSeconds];
14181439

14191440
// Setup 2nd subscriber
14201441
subscribeExpectation = [self expectationWithDescription:@"subscribe CurrentLevel attribute"];
1421-
MTRSubscribeParams * myParams = [[MTRSubscribeParams alloc] initWithMinInterval:@(2) maxInterval:@(10)];
1442+
MTRSubscribeParams * myParams = [[MTRSubscribeParams alloc] initWithMinInterval:@(0) maxInterval:@(10)];
14221443
myParams.replaceExistingSubscriptions = NO;
14231444
[device subscribeToAttributesWithEndpointID:@1
14241445
clusterID:@8
@@ -1443,7 +1464,31 @@ - (void)test012_SubscribeKeepingPreviousSubscription
14431464
// Wait till establishment
14441465
[self waitForExpectations:@[ subscribeExpectation ] timeout:kTimeoutInSeconds];
14451466

1446-
// Send command to clear attribute state
1467+
// If we were initially on, set up expectations for report that we have been
1468+
// turned off, so we make sure that comes through before we do the rest of
1469+
// the test.
1470+
XCTestExpectation * offReportExpectation;
1471+
if (initialOnOffState == YES) {
1472+
offReportExpectation = [self expectationWithDescription:@"OnOff attribute has become false."];
1473+
firstReportHandler = ^(id _Nullable values, NSError * _Nullable error) {
1474+
XCTAssertNil(error);
1475+
1476+
{
1477+
XCTAssertTrue([values isKindOfClass:[NSArray class]]);
1478+
NSDictionary * result = values[0];
1479+
MTRAttributePath * path = result[@"attributePath"];
1480+
XCTAssertEqual([path.endpoint unsignedIntegerValue], 1);
1481+
XCTAssertEqual([path.cluster unsignedIntegerValue], 6);
1482+
XCTAssertEqual([path.attribute unsignedIntegerValue], 0);
1483+
XCTAssertTrue([result[@"data"] isKindOfClass:[NSDictionary class]]);
1484+
XCTAssertTrue([result[@"data"][@"type"] isEqualToString:@"Boolean"]);
1485+
XCTAssertEqual([result[@"data"][@"value"] boolValue], NO);
1486+
}
1487+
[offReportExpectation fulfill];
1488+
};
1489+
}
1490+
1491+
// Ensure that we are in the "off" state.
14471492
XCTestExpectation * clearCommandExpectation = [self expectationWithDescription:@"Clearing command invoked"];
14481493
[device invokeCommandWithEndpointID:@1
14491494
clusterID:@6
@@ -1452,7 +1497,7 @@ - (void)test012_SubscribeKeepingPreviousSubscription
14521497
timedInvokeTimeout:nil
14531498
queue:queue
14541499
completion:^(id _Nullable values, NSError * _Nullable error) {
1455-
NSLog(@"invoke command: On values: %@, error: %@", values, error);
1500+
NSLog(@"invoke command: Off values: %@, error: %@", values, error);
14561501

14571502
XCTAssertNil(error);
14581503

@@ -1471,6 +1516,9 @@ - (void)test012_SubscribeKeepingPreviousSubscription
14711516
[clearCommandExpectation fulfill];
14721517
}];
14731518
[self waitForExpectations:@[ clearCommandExpectation ] timeout:kTimeoutInSeconds];
1519+
if (offReportExpectation) {
1520+
[self waitForExpectations:@[ offReportExpectation ] timeout:kTimeoutInSeconds];
1521+
}
14741522

14751523
// Set up expectations for report
14761524
XCTestExpectation * reportExpectation = [self expectationWithDescription:@"The 1st subscriber received OnOff attribute report"];
@@ -1622,7 +1670,7 @@ - (void)test013_TimedWriteAttribute
16221670
// subscribe, which should get the new value at the timeout
16231671
expectation = [self expectationWithDescription:@"Subscribed"];
16241672
__block void (^reportHandler)(id _Nullable values, NSError * _Nullable error);
1625-
__auto_type * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(2) maxInterval:@(10)];
1673+
__auto_type * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(0) maxInterval:@(10)];
16261674
[device subscribeToAttributesWithEndpointID:@1
16271675
clusterID:@8
16281676
attributeID:@17

0 commit comments

Comments
 (0)