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

[Darwin tests] Fix testAnySharedRemoteController and testReadClusterStateCacheFailure #23663

Merged
Merged
Show file tree
Hide file tree
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
13 changes: 8 additions & 5 deletions src/darwin/Framework/CHIP/MTRDeviceControllerOverXPC.m
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ - (BOOL)getBaseDevice:(uint64_t)deviceID
// under here if we don't have a controller id aleady, so make sure we do
// that.
[self fetchControllerIdWithQueue:queue
completion:^(id _Nullable controllerID, NSError * _Nullable error) {
completion:^(id _Nullable controllerID, MTRDeviceControllerXPCProxyHandle * _Nullable handle,
NSError * _Nullable error) {
if (error != nil) {
completionHandler(nil, error);
return;
Expand All @@ -172,6 +173,9 @@ - (BOOL)getBaseDevice:(uint64_t)deviceID

- (void)fetchControllerIdWithQueue:(dispatch_queue_t)queue completion:(MTRFetchControllerIDCompletion)completion
{
// Capture the proxy handle so that it won't be released prior to block call.
__block MTRDeviceControllerXPCProxyHandle * handleRetainer = nil;

dispatch_async(_workQueue, ^{
dispatch_group_t group = dispatch_group_create();
if (!self.controllerID) {
Expand All @@ -184,10 +188,9 @@ - (void)fetchControllerIdWithQueue:(dispatch_queue_t)queue completion:(MTRFetchC
MTR_LOG_ERROR("Failed to fetch any shared remote controller");
} else {
self.controllerID = controller;
handleRetainer = handle;
}
dispatch_group_leave(group);
__auto_type handleRetainer = handle;
(void) handleRetainer;
}];
} else {
MTR_LOG_ERROR("XPC disconnected while retrieving any shared remote controller");
Expand All @@ -197,9 +200,9 @@ - (void)fetchControllerIdWithQueue:(dispatch_queue_t)queue completion:(MTRFetchC
}
dispatch_group_notify(group, queue, ^{
if (self.controllerID) {
completion(self.controllerID, nil);
completion(self.controllerID, handleRetainer, nil);
} else {
completion(nil, [NSError errorWithDomain:MTRErrorDomain code:MTRErrorCodeGeneralError userInfo:nil]);
completion(nil, nil, [NSError errorWithDomain:MTRErrorDomain code:MTRErrorCodeGeneralError userInfo:nil]);
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

NS_ASSUME_NONNULL_BEGIN

typedef void (^MTRFetchControllerIDCompletion)(id _Nullable controllerID, NSError * _Nullable error);
typedef void (^MTRFetchControllerIDCompletion)(
id _Nullable controllerID, MTRDeviceControllerXPCProxyHandle * _Nullable handle, NSError * _Nullable error);

@interface MTRDeviceControllerOverXPC ()

Expand Down
Loading