Skip to content

Commit 4390897

Browse files
committed
Clean up the tests
1 parent e3972f6 commit 4390897

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

src/darwin/Framework/CHIP/MTRDeviceControllerDataStore.mm

+7-1
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ - (BOOL)_deleteEndpointIndexForNodeID:(NSNumber *)nodeID
475475
return NO;
476476
}
477477

478+
478479
return [self _removeAttributeCacheValueForKey:[self _endpointIndexKeyForNodeID:nodeID]];
479480
}
480481

@@ -559,6 +560,7 @@ - (BOOL)_deleteClusterDataForNodeID:(NSNumber *)nodeID endpointID:(NSNumber *)en
559560
MTR_LOG_ERROR("%s: unexpected nil input", __func__);
560561
return NO;
561562
}
563+
562564
return [self _removeAttributeCacheValueForKey:[self _clusterDataKeyForNodeID:nodeID endpointID:endpointID clusterID:clusterID]];
563565
}
564566

@@ -749,7 +751,11 @@ - (void)removeAttributes:(NSSet<NSNumber *> *)attributes fromCluster:(MTRCluster
749751
for (NSNumber * attribute in attributes) {
750752
[clusterData removeValueForAttribute:attribute];
751753
}
752-
[self _storeClusterData:clusterData forNodeID:nodeID endpointID:path.endpoint clusterID:path.cluster];
754+
BOOL success = [self _storeClusterData:clusterData forNodeID:nodeID endpointID:path.endpoint clusterID:path.cluster];
755+
if (!success) {
756+
MTR_LOG_ERROR("removeAttributes: _storeClusterData failed for node 0x%016llX endpoint %u", nodeID.unsignedLongLongValue, path.endpoint.unsignedShortValue);
757+
}
758+
MTR_LOG("removeAttributes: Deleted attributes %@ from endpoint %u cluster 0x%08lX for node 0x%016llX successfully", attributes, path.endpoint.unsignedShortValue, path.cluster.unsignedLongValue, nodeID.unsignedLongLongValue);
753759
}
754760

755761
- (void)clearAllStoredClusterData

src/darwin/Framework/CHIPTests/MTRPerControllerStorageTests.m

+15-12
Original file line numberDiff line numberDiff line change
@@ -2278,6 +2278,7 @@ - (void)test011_testDataStorageUpdatesWhenRemovingEndpoints
22782278
// just checking data storage should suffice here.
22792279
dispatch_sync(self->_storageQueue, ^{
22802280
XCTAssertTrue([[controller.controllerDataStore _fetchEndpointIndexForNodeID:deviceID] isEqualToArray:testEndpoints]);
2281+
22812282
// Populate the initialClusterIndex to use as a reference for all cluster paths later.
22822283
for (NSNumber * endpoint in testEndpoints) {
22832284
[initialClusterIndex setObject:[controller.controllerDataStore _fetchClusterIndexForNodeID:deviceID endpointID:endpoint] forKey:endpoint];
@@ -2300,7 +2301,7 @@ - (void)test011_testDataStorageUpdatesWhenRemovingEndpoints
23002301
// Inject a fake attribute report deleting endpoint 2 from the parts list at the root endpoint.
23012302
dataVersionForPartsList = [NSNumber numberWithUnsignedLongLong:(dataVersionForPartsList.unsignedLongLongValue + 1)];
23022303

2303-
// Delete the last endpoint from the attribute value in parts list.
2304+
// Delete endpoint 2 from the attribute value in parts list.
23042305
NSNumber * toBeDeletedEndpoint = @2;
23052306
__block id endpointData =
23062307
@{
@@ -2330,7 +2331,8 @@ - (void)test011_testDataStorageUpdatesWhenRemovingEndpoints
23302331
for (NSDictionary<NSString *, id> * attributeDict in attributeReport) {
23312332
MTRAttributePath * attributePath = attributeDict[MTRAttributePathKey];
23322333
XCTAssertNotNil(attributePath);
2333-
// Get the new updated parts list value to get the test endpoints.
2334+
2335+
// Get the new updated parts list value to get the new test endpoints.
23342336
if ([attributePath.endpoint isEqualToNumber:rootEndpoint] && attributePath.cluster.unsignedLongValue == MTRClusterIDTypeDescriptorID && attributePath.attribute.unsignedLongValue == MTRAttributeIDTypeClusterDescriptorAttributePartsListID) {
23352337
testDataForPartsList = attributeDict[MTRDataKey];
23362338
XCTAssertNotNil(testDataForPartsList);
@@ -2346,7 +2348,7 @@ - (void)test011_testDataStorageUpdatesWhenRemovingEndpoints
23462348
XCTAssertNotNil(testClusterDataValueForPartsList);
23472349
testEndpoints = [self getEndpointArrayFromPartsList:testDataForPartsList forDevice:device];
23482350

2349-
// Make sure that the cluster data in the data storage for the cluster for endpoints 0 and 1 are present but not for endpoint 2.
2351+
// Make sure that the cluster data in the data storage for endpoints 0 and 1 are present but not for endpoint 2.
23502352
// We do not need to check _persistedClusterData here. _persistedClusterData will be paged in from storage when needed so
23512353
// just checking data storage should suffice here.
23522354
dispatch_sync(self->_storageQueue, ^{
@@ -2398,11 +2400,10 @@ - (void)test012_testDataStorageUpdatesWhenRemovingClusters
23982400

23992401
// This test will do the following -
24002402
// 1. Get the data version and attribute value of the server list for endpoint 1 to inject a fake report. The attribute report will delete cluster ID - MTRClusterIDTypeIdentifyID.
2401-
// That should cause the cluster to be removed from cluster index and cluster data for that cluster to be removed from data storage.
2402-
// 2. The data store is populated with MTRClusterIDTypeIdentifyID in the cluster index and cluster data initially.
2403-
// Also _persistedClusters and _persistedClusterData has the cluster path and cluster data for cluster ID - MTRClusterIDTypeIdentifyID.
2403+
// That should cause the cluster to be removed from cluster index for endpoint 1 and the cluster data for the removed cluster should be cleared from data storage.
2404+
// 2. The data store is populated with MTRClusterIDTypeIdentifyID in the cluster index and cluster data for endpoint 1 initially.
24042405
// 3. After the fake attribute report is injected with deleted cluster ID - MTRClusterIDTypeIdentifyID, make sure the data store is still populated with cluster index and
2405-
// cluster data for other clusters at endpoint 1 but not the deleted cluster.
2406+
// cluster data for all other clusters at endpoint 1 but not the deleted cluster.
24062407
__block NSMutableArray * testClusterDataValue;
24072408
delegate.onAttributeDataReceived = ^(NSArray<NSDictionary<NSString *, id> *> * attributeReport) {
24082409
attributeReportsReceived += attributeReport.count;
@@ -2438,7 +2439,7 @@ - (void)test012_testDataStorageUpdatesWhenRemovingClusters
24382439
XCTAssertNotNil(testClusterDataValue);
24392440

24402441
// Make sure that the cluster data in the data storage has cluster ID - MTRClusterIDTypeIdentifyID in the cluster index for endpoint 1
2441-
// and cluster data for MTRClusterIDTypeIdentifyID exists
2442+
// and cluster data for MTRClusterIDTypeIdentifyID exists.
24422443
// We do not need to check _persistedClusterData here. _persistedClusterData will be paged in from storage when needed so
24432444
// just checking data storage should suffice here.
24442445
dispatch_sync(self->_storageQueue, ^{
@@ -2477,6 +2478,7 @@ - (void)test012_testDataStorageUpdatesWhenRemovingClusters
24772478
};
24782479

24792480
delegate.onReportEnd = ^{
2481+
24802482
// Make sure that the cluster data does not have cluster ID - MTRClusterIDTypeIdentifyID in the cluster index for endpoint 1
24812483
// and cluster data for MTRClusterIDTypeIdentifyID is nil.
24822484
// We do not need to check _persistedClusterData here. _persistedClusterData will be paged in from storage when needed so
@@ -2528,9 +2530,9 @@ - (void)test013_testDataStorageUpdatesWhenRemovingAttributes
25282530
__block NSMutableArray * testClusterDataValue;
25292531

25302532
// This test will do the following -
2531-
// 1. Get the data version and attribute value of the attribute list for endpoint 1 to inject a fake report with attribute 1 removed.
2533+
// 1. Get the data version and attribute value of the attribute list for endpoint 1 to inject a fake report with attribute 1 removed from MTRClusterIDTypeIdentifyID.
25322534
// 2. The data store is populated with cluster data for MTRClusterIDTypeIdentifyID cluster and has all attributes including attribute 1.
2533-
// 3. After the fake attribute report is injected, make sure the data store is populated with cluster data for MTRClusterIDTypeIdentifyID
2535+
// 3. After the fake attribute report is injected, make sure the data store is populated with cluster data for all attributes in MTRClusterIDTypeIdentifyID
25342536
// cluster except for attribute 1 which has been deleted.
25352537
delegate.onAttributeDataReceived = ^(NSArray<NSDictionary<NSString *, id> *> * attributeReport) {
25362538
attributeReportsReceived += attributeReport.count;
@@ -2565,7 +2567,7 @@ - (void)test013_testDataStorageUpdatesWhenRemovingAttributes
25652567

25662568
// Make sure that the cluster data in the data storage is populated with cluster data for MTRClusterIDTypeIdentifyID cluster
25672569
// and has all attributes including attribute 1.
2568-
// We will be paged in the cluster data from storage to check the above.
2570+
// We will page in the cluster data from storage to check the above.
25692571
MTRClusterPath * path = [MTRClusterPath clusterPathWithEndpointID:testEndpoint clusterID:cluster];
25702572

25712573
if ([cluster isEqualToNumber:@(MTRClusterIDTypeIdentifyID)]) {
@@ -2615,9 +2617,10 @@ - (void)test013_testDataStorageUpdatesWhenRemovingAttributes
26152617
};
26162618

26172619
delegate.onReportEnd = ^{
2620+
26182621
// Make sure that the cluster data in the data storage is populated with cluster data for MTRClusterIDTypeIdentifyID cluster
26192622
// and has all attributes except attribute 1 which was deleted.
2620-
// We will be paged in the cluster data from storage to check the above.
2623+
// We will page in the cluster data from storage to check the above.
26212624
dispatch_sync(self->_storageQueue, ^{
26222625
initialClusterIndex = [[controller.controllerDataStore _fetchClusterIndexForNodeID:deviceID endpointID:testEndpoint] mutableCopy];
26232626
XCTAssertNotNil(initialClusterIndex);

0 commit comments

Comments
 (0)