Skip to content

Commit

Permalink
Ensure the connection and the disconnect handler are accessed from th…
Browse files Browse the repository at this point in the history
…e same dispatch queue in MTRProtocolTests.m (#22732)
  • Loading branch information
vivien-apple committed Sep 19, 2022
1 parent 239f09e commit 2466360
Showing 1 changed file with 15 additions and 9 deletions.
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

0 comments on commit 2466360

Please sign in to comment.