Skip to content

Commit

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

* [Darwin Tests] Fix testAnySharedRemoteController

* [Darwin Tests] Fix testReadClusterStateCacheFailure
  • Loading branch information
vivien-apple authored Sep 23, 2022
1 parent efb8f2f commit 2aaf589
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 256 deletions.
10 changes: 6 additions & 4 deletions src/darwin/Framework/CHIP/MTRDeviceControllerOverXPC.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ - (nullable MTRBaseDevice *)deviceBeingCommissionedWithNodeID:(NSNumber *)nodeID

- (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 @@ -100,10 +103,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 @@ -113,9 +115,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 2aaf589

Please sign in to comment.