Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure the connection and the disconnect handler are accessed from th… #22732

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions src/darwin/Framework/CHIPTests/MTRXPCProtocolTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,19 @@ - (BOOL)listener:(NSXPCListener *)listener shouldAcceptNewConnection:(NSXPCConne
newConnection.remoteObjectInterface = _clientInterface;
newConnection.exportedObject = self;
newConnection.invalidationHandler = ^{
NSLog(@"XPC connection disconnected");
self.xpcConnection = nil;
if (self.xpcDisconnectExpectation) {
[self.xpcDisconnectExpectation fulfill];
self.xpcDisconnectExpectation = nil;
}
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"XPC connection disconnected");
self.xpcConnection = nil;
if (self.xpcDisconnectExpectation) {
[self.xpcDisconnectExpectation fulfill];
self.xpcDisconnectExpectation = nil;
}
});
};
_xpcConnection = newConnection;
[newConnection resume];
dispatch_async(dispatch_get_main_queue(), ^{
self.xpcConnection = newConnection;
[newConnection resume];
});
return YES;
}

Expand Down Expand Up @@ -2263,6 +2267,8 @@ - (void)testReadClusterStateCacheSuccess
completion([MTRDeviceController encodeXPCResponseValues:myValues], nil);
};

_xpcDisconnectExpectation = [self expectationWithDescription:@"XPC Disconnected"];

[clusterStateCacheContainer subscribeWithDeviceController:_remoteDeviceController
deviceID:@(myNodeId)
params:nil
Expand All @@ -2272,7 +2278,7 @@ - (void)testReadClusterStateCacheSuccess
XCTAssertNil(error);
[subscribeExpectation fulfill];
}];
[self waitForExpectations:@[ subscribeExpectation ] timeout:kTimeoutInSeconds];
[self waitForExpectations:@[ subscribeExpectation, _xpcDisconnectExpectation ] timeout:kTimeoutInSeconds];

_xpcDisconnectExpectation = [self expectationWithDescription:@"XPC Disconnected"];
[clusterStateCacheContainer
Expand Down