Skip to content

Commit

Permalink
Fixed unit test race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
jtung-apple committed Mar 13, 2024
1 parent 1191da7 commit 62ff45e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/darwin/Framework/CHIPTests/MTRPerControllerStorageTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -1142,16 +1142,20 @@ - (void)test008_TestDataStoreDirect
// Test MTRDeviceControllerDataStore _pruneEmptyStoredAttributesBranches
// - Clear cache
// - Store an attribute
// - Manually delete it from the user defaults
// - Manually delete it from the test storage delegate
// - Call _pruneEmptyStoredAttributesBranches
[controller.controllerDataStore clearAllStoredAttributes];

NSArray * testAttribute = @[
@{ MTRAttributePathKey : [MTRAttributePath attributePathWithEndpointID:@(1) clusterID:@(1) attributeID:@(1)], MTRDataKey : @ { MTRTypeKey : MTRUnsignedIntegerValueType, MTRValueKey : @(111) } },
];
[controller.controllerDataStore storeAttributeValues:testAttribute forNodeID:@(2001)];
NSString * testAttributeValueKey = [controller.controllerDataStore _attributeValueKeyForNodeID:@(2001) endpointID:@(1) clusterID:@(1) attributeID:@(1)];
[storageDelegate controller:controller removeValueForKey:testAttributeValueKey securityLevel:MTRStorageSecurityLevelSecure sharingType:MTRStorageSharingTypeNotShared];

// store is async, so remove on the same queue to ensure order
dispatch_sync(_storageQueue, ^{
NSString * testAttributeValueKey = [controller.controllerDataStore _attributeValueKeyForNodeID:@(2001) endpointID:@(1) clusterID:@(1) attributeID:@(1)];
[storageDelegate controller:controller removeValueForKey:testAttributeValueKey securityLevel:MTRStorageSecurityLevelSecure sharingType:MTRStorageSharingTypeNotShared];
});
[controller.controllerDataStore unitTestPruneEmptyStoredAttributesBranches];

// Now check the indexes are pruned
Expand Down

0 comments on commit 62ff45e

Please sign in to comment.