Skip to content

Commit

Permalink
Fix XPC connection failure handling (#16063)
Browse files Browse the repository at this point in the history
for Darwin CHIPDeviceController.
  • Loading branch information
kpark-apple authored and pull[bot] committed Jul 12, 2023
1 parent ae7232b commit f8e203b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ - (void)getProxyHandleWithCompletion:(void (^)(dispatch_queue_t queue,
if (!xpcConnection) {
CHIP_LOG_ERROR("Cannot connect to XPC server for remote controller");
completion(self.workQueue, nil);
return;
}
xpcConnection.remoteObjectInterface = self.remoteDeviceServerProtocol;
xpcConnection.exportedInterface = self.remoteDeviceClientProtocol;
Expand Down
35 changes: 35 additions & 0 deletions src/darwin/Framework/CHIPTests/CHIPXPCProtocolTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -1823,4 +1823,39 @@ - (void)testReadAttributeCacheFailure
XCTAssertNil(_xpcConnection);
}

- (void)testXPCConnectionFailure
{
uint64_t myNodeId = 9876543210;
NSUInteger myEndpointId = 100;
NSUInteger myClusterId = 200;
NSUInteger myAttributeId = 300;
XCTestExpectation * responseExpectation = [self expectationWithDescription:@"Read response received"];

// Test with a device controller which wouldn't connect to XPC listener successfully
__auto_type failingDeviceController = [CHIPDeviceController sharedControllerWithId:_controllerUUID
xpcConnectBlock:^NSXPCConnection * {
return nil;
}];

[failingDeviceController getConnectedDevice:myNodeId
queue:dispatch_get_main_queue()
completionHandler:^(CHIPDevice * _Nullable device, NSError * _Nullable error) {
XCTAssertNotNil(device);
XCTAssertNil(error);
NSLog(@"Device acquired. Reading...");
[device readAttributeWithEndpointId:myEndpointId
clusterId:myClusterId
attributeId:myAttributeId
clientQueue:dispatch_get_main_queue()
completion:^(id _Nullable value, NSError * _Nullable error) {
NSLog(@"Read value: %@", value);
XCTAssertNil(value);
XCTAssertNotNil(error);
[responseExpectation fulfill];
}];
}];

[self waitForExpectations:@[ responseExpectation ] timeout:kTimeoutInSeconds];
}

@end

0 comments on commit f8e203b

Please sign in to comment.