Skip to content

Commit 9a4f3e4

Browse files
committed
Fix unit test
1 parent 9ad4922 commit 9a4f3e4

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

src/darwin/Framework/CHIPTests/MTRDeviceTests.m

+8-3
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ - (void)tearDown
242242
// existing subscriptions and then fail out due to requesting a subscribe to
243243
// a nonexistent cluster.
244244
if (mConnectedDevice != nil) {
245+
NSLog(@"JEFFTEST: teardown - unsubscribe");
245246
dispatch_queue_t queue = dispatch_get_main_queue();
246247

247248
MTRSubscribeParams * params = [[MTRSubscribeParams alloc] initWithMinInterval:@(0) maxInterval:@(10)];
@@ -3679,7 +3680,7 @@ - (void)test036_TestStorageBehaviorConfiguration
36793680

36803681
__auto_type * device = [MTRDevice deviceWithNodeID:kDeviceId deviceController:sController];
36813682

3682-
__auto_type * delegate = [[MTRDeviceTestDelegate alloc] init];
3683+
__auto_type * delegate = [[MTRDeviceTestDelegateWithSubscriptionSetupOverride alloc] init];
36833684
__block os_unfair_lock lock = OS_UNFAIR_LOCK_INIT;
36843685
__block NSDate * reportEndTime = nil;
36853686
__block NSDate * dataPersistedTime = nil;
@@ -3832,9 +3833,10 @@ - (void)test036_TestStorageBehaviorConfiguration
38323833
os_unfair_lock_lock(&lock);
38333834
reportToPersistenceDelay = [dataPersistedTime timeIntervalSinceDate:reportEndTime];
38343835
os_unfair_lock_unlock(&lock);
3835-
// Check delay exists and approximately base delay times 3
3836+
// Check delay exists and at least base delay times 3
38363837
XCTAssertGreaterThan(reportToPersistenceDelay, baseTestDelayTime * 3 * 0.9);
3837-
XCTAssertLessThan(reportToPersistenceDelay, baseTestDelayTime * 3 * 1.3); // larger upper limit in case machine is slow
3838+
// upper limit at most max delay times full multiplier + extra in case machine is slow
3839+
XCTAssertLessThan(reportToPersistenceDelay, baseTestDelayTime * 2 * 5 * 1.3);
38383840

38393841
// Test 4: test reporting excessively, and see that persistence does not happen until
38403842
// reporting frequency goes back above the threshold
@@ -3888,6 +3890,9 @@ - (void)test036_TestStorageBehaviorConfiguration
38883890
[device unitTestInjectAttributeReport:attributeReport fromSubscription:YES];
38893891

38903892
[self waitForExpectations:@[ dataPersisted4 ] timeout:60];
3893+
3894+
delegate.onReportEnd = nil;
3895+
delegate.onClusterDataPersisted = nil;
38913896
}
38923897

38933898
@end

src/darwin/Framework/CHIPTests/TestHelpers/MTRDeviceTestDelegate.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ typedef void (^MTRDeviceTestDelegateDataHandler)(NSArray<NSDictionary<NSString *
3434
@property (nonatomic) BOOL pretendThreadEnabled;
3535
@property (nonatomic, nullable) dispatch_block_t onSubscriptionPoolDequeue;
3636
@property (nonatomic, nullable) dispatch_block_t onSubscriptionPoolWorkComplete;
37-
@property (nonatomic) BOOL skipSetupSubscription;
3837
@property (nonatomic, nullable) dispatch_block_t onClusterDataPersisted;
3938
@end
4039

40+
@interface MTRDeviceTestDelegateWithSubscriptionSetupOverride : MTRDeviceTestDelegate
41+
@property (nonatomic) BOOL skipSetupSubscription;
42+
@end
43+
4144
NS_ASSUME_NONNULL_END

src/darwin/Framework/CHIPTests/TestHelpers/MTRDeviceTestDelegate.m

+9-5
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,6 @@ - (void)unitTestSubscriptionPoolWorkComplete:(MTRDevice *)device
9696
}
9797
}
9898

99-
- (BOOL)unitTestShouldSetUpSubscriptionForDevice:(MTRDevice *)device
100-
{
101-
return !_skipSetupSubscription;
102-
}
103-
10499
- (void)unitTestClusterDataPersisted:(MTRDevice *)device
105100
{
106101
if (self.onClusterDataPersisted != nil) {
@@ -109,3 +104,12 @@ - (void)unitTestClusterDataPersisted:(MTRDevice *)device
109104
}
110105

111106
@end
107+
108+
@implementation MTRDeviceTestDelegateWithSubscriptionSetupOverride
109+
110+
- (BOOL)unitTestShouldSetUpSubscriptionForDevice:(MTRDevice *)device
111+
{
112+
return !_skipSetupSubscription;
113+
}
114+
115+
@end

0 commit comments

Comments
 (0)