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

Fix auto resubcribe condition for in Darwin subscribeToAttributesWithEndpointID. #23554

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
2 changes: 1 addition & 1 deletion src/darwin/Framework/CHIP/MTRBaseDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ - (void)subscribeToAttributesWithEndpointID:(NSNumber * _Nullable)endpointID
auto readClient = Platform::New<app::ReadClient>(
engine, exchangeManager, callback->GetBufferedCallback(), chip::app::ReadClient::InteractionType::Subscribe);

if (params.replaceExistingSubscriptions) {
if (!params.resubscribeIfLost) {
err = readClient->SendRequest(readParams);
} else {
err = readClient->SendAutoResubscribeRequest(std::move(readParams));
Expand Down
65 changes: 65 additions & 0 deletions src/darwin/Framework/CHIPTests/MTRDeviceTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -1254,6 +1254,8 @@ - (void)test015_FailedSubscribeWithQueueAcrossShutdown
__auto_type clusterStateCacheContainer = [[MTRAttributeCacheContainer alloc] init];
__auto_type * params = [[MTRSubscribeParams alloc] init];
params.resubscribeIfLost = NO;
params.replaceExistingSubscriptions = NO; // Not strictly needed, but checking that doing this does not
// affect this subscription erroring out correctly.
[device subscribeWithQueue:queue
minInterval:1
maxInterval:2
Expand Down Expand Up @@ -1292,6 +1294,7 @@ - (void)test015_FailedSubscribeWithQueueAcrossShutdown

// Create second subscription which will cancel the first subscription. We
// can use a non-existent path here to cut down on the work that gets done.
params.replaceExistingSubscriptions = YES;
[device subscribeAttributeWithEndpointId:@10000
clusterId:@6
attributeId:@0
Expand Down Expand Up @@ -1350,6 +1353,7 @@ - (void)test016_FailedSubscribeWithCacheReadDuringFailure

// Create second subscription which will cancel the first subscription. We
// can use a non-existent path here to cut down on the work that gets done.
params.replaceExistingSubscriptions = YES;
[device subscribeAttributeWithEndpointId:@10000
clusterId:@6
attributeId:@0
Expand Down Expand Up @@ -1386,6 +1390,67 @@ - (void)test017_TestMTRDeviceBasics
[self waitForExpectations:@[ subscriptionExpectation ] timeout:60];
}

- (void)test018_SubscriptionErrorWhenNotResubscribing
{
#if MANUAL_INDIVIDUAL_TEST
[self initStack];
[self waitForCommissionee];
#endif
MTRBaseDevice * device = GetConnectedDevice();
dispatch_queue_t queue = dispatch_get_main_queue();

XCTestExpectation * firstSubscribeExpectation = [self expectationWithDescription:@"First subscription complete"];
XCTestExpectation * errorExpectation = [self expectationWithDescription:@"First subscription errored out"];

// Subscribe
MTRSubscribeParams * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(1) maxInterval:@(10)];
params.resubscribeIfLost = NO;
params.replaceExistingSubscriptions = NO; // Not strictly needed, but checking that doing this does not
// affect this subscription erroring out correctly.
__block BOOL subscriptionEstablished = NO;
[device subscribeToAttributesWithEndpointID:@1
clusterID:@6
attributeID:@0
params:params
queue:queue
reportHandler:^(id _Nullable values, NSError * _Nullable error) {
if (subscriptionEstablished) {
// We should only get an error here.
XCTAssertNil(values);
XCTAssertNotNil(error);
[errorExpectation fulfill];
} else {
XCTAssertNotNil(values);
XCTAssertNil(error);
}
}
subscriptionEstablished:^{
NSLog(@"subscribe attribute: OnOff established");
XCTAssertFalse(subscriptionEstablished);
subscriptionEstablished = YES;
[firstSubscribeExpectation fulfill];
}];

// Wait till establishment
[self waitForExpectations:@[ firstSubscribeExpectation ] timeout:kTimeoutInSeconds];

// Create second subscription which will cancel the first subscription. We
// can use a non-existent path here to cut down on the work that gets done.
params.replaceExistingSubscriptions = YES;
[device subscribeAttributeWithEndpointId:@10000
clusterId:@6
attributeId:@0
minInterval:@(1)
maxInterval:@(2)
params:params
clientQueue:queue
reportHandler:^(id _Nullable values, NSError * _Nullable error) {
}
subscriptionEstablished:^() {
}];
[self waitForExpectations:@[ errorExpectation ] timeout:60];
}

- (void)test900_SubscribeAllAttributes
{
#if MANUAL_INDIVIDUAL_TEST
Expand Down