Skip to content

Commit

Permalink
[Darwin tests] Fix testAnySharedRemoteController and testReadClusterS…
Browse files Browse the repository at this point in the history
…tateCacheFailure (#23663)

This is a re-landing of PR #22838.

* [Darwin Tests] Fix testAnySharedRemoteController

* [Darwin Tests] Fix testReadClusterStateCacheFailure

Co-authored-by: Vivien Nicolas <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Jul 31, 2023
1 parent c1da792 commit c23d916
Show file tree
Hide file tree
Showing 4 changed files with 209 additions and 261 deletions.
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

0 comments on commit c23d916

Please sign in to comment.