Skip to content

Commit 79348a8

Browse files
Stop running the MTRDevice dealloc test when pool width is not 1.
This fails intermittently in testSubscriptionPoolManyDevices, but more importantly: this dealloc test only makes sense in the width-1 case, because if the pool width is not 1 then the test is not testing anything (because nothing gets blocked on the one badly behaving thing if it does behave badly).
1 parent ebe16b7 commit 79348a8

File tree

1 file changed

+34
-32
lines changed

1 file changed

+34
-32
lines changed

src/darwin/Framework/CHIPTests/MTRPerControllerStorageTests.m

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2890,38 +2890,40 @@ - (void)doTestSubscriptionPoolWithSize:(NSInteger)subscriptionPoolSize deviceOnb
28902890
};
28912891
}
28922892

2893-
// We have one fake device, which we use an invalid node ID for, that we use
2894-
// to test what happens if a device is deallocated while its subscription
2895-
// work item is queued.
2896-
//
2897-
// Schedule a job in the controller's pool that will not complete until the
2898-
// fake device is deallocated.
2899-
__auto_type * fakeDeviceDeletedExpectation = [self expectationWithDescription:@"Fake device deleted"];
2900-
MTRAsyncWorkItem * blockingWorkItem = [[MTRAsyncWorkItem alloc] initWithQueue:queue];
2901-
[blockingWorkItem setReadyHandler:^(id _Nonnull context, NSInteger retryCount, MTRAsyncWorkCompletionBlock _Nonnull completion) {
2902-
[self waitForExpectations:@[ fakeDeviceDeletedExpectation ] timeout:kTimeoutInSeconds];
2903-
completion(MTRAsyncWorkComplete);
2904-
}];
2905-
[controller.concurrentSubscriptionPool enqueueWorkItem:blockingWorkItem description:@"Waiting for fake device deletion"];
2906-
2907-
// Make sure the delegate for the fake device does not go away before the
2908-
// fake device does, so keep it out of the @autoreleasepool block.
2909-
MTRDeviceTestDelegate * fakeDeviceDelegate = [[MTRDeviceTestDelegate alloc] init];
2910-
fakeDeviceDelegate.pretendThreadEnabled = YES;
2911-
2912-
@autoreleasepool {
2913-
// Create our fake device and have it dealloc before the blocking WorkItem
2914-
// completes and hence before its subscription work item gets a chance
2915-
// to run (in the width-1 case).
2916-
2917-
// onSubscriptionCallbackDelete is called from dealloc
2918-
fakeDeviceDelegate.onSubscriptionCallbackDelete = ^{
2919-
[fakeDeviceDeletedExpectation fulfill];
2920-
};
2921-
2922-
NSNumber * fakeDeviceID = @(0xFFFFFFFFFFFFFFFF);
2923-
__auto_type * device = [MTRDevice deviceWithNodeID:fakeDeviceID controller:controller];
2924-
[device setDelegate:fakeDeviceDelegate queue:queue];
2893+
if (subscriptionPoolSize == 1) {
2894+
// We have one fake device, which we use an invalid node ID for, that we use
2895+
// to test what happens if a device is deallocated while its subscription
2896+
// work item is queued. It should not block other things from running.
2897+
//
2898+
// Schedule a job in the controller's pool that will not complete until the
2899+
// fake device is deallocated.
2900+
__auto_type * fakeDeviceDeletedExpectation = [self expectationWithDescription:@"Fake device deleted"];
2901+
MTRAsyncWorkItem * blockingWorkItem = [[MTRAsyncWorkItem alloc] initWithQueue:queue];
2902+
[blockingWorkItem setReadyHandler:^(id _Nonnull context, NSInteger retryCount, MTRAsyncWorkCompletionBlock _Nonnull completion) {
2903+
[self waitForExpectations:@[ fakeDeviceDeletedExpectation ] timeout:kTimeoutInSeconds];
2904+
completion(MTRAsyncWorkComplete);
2905+
}];
2906+
[controller.concurrentSubscriptionPool enqueueWorkItem:blockingWorkItem description:@"Waiting for fake device deletion"];
2907+
2908+
// Make sure the delegate for the fake device does not go away before the
2909+
// fake device does, so keep it out of the @autoreleasepool block.
2910+
MTRDeviceTestDelegate * fakeDeviceDelegate = [[MTRDeviceTestDelegate alloc] init];
2911+
fakeDeviceDelegate.pretendThreadEnabled = YES;
2912+
2913+
@autoreleasepool {
2914+
// Create our fake device and have it dealloc before the blocking WorkItem
2915+
// completes and hence before its subscription work item gets a chance
2916+
// to run (in the width-1 case).
2917+
2918+
// onSubscriptionCallbackDelete is called from dealloc
2919+
fakeDeviceDelegate.onSubscriptionCallbackDelete = ^{
2920+
[fakeDeviceDeletedExpectation fulfill];
2921+
};
2922+
2923+
NSNumber * fakeDeviceID = @(0xFFFFFFFFFFFFFFFF);
2924+
__auto_type * device = [MTRDevice deviceWithNodeID:fakeDeviceID controller:controller];
2925+
[device setDelegate:fakeDeviceDelegate queue:queue];
2926+
}
29252927
}
29262928

29272929
for (NSNumber * deviceID in orderedDeviceIDs) {

0 commit comments

Comments
 (0)