@@ -383,6 +383,7 @@ - (BOOL)unitTestPretendThreadEnabled:(MTRDevice *)device;
383
383
- (void )unitTestSubscriptionPoolDequeue : (MTRDevice *)device ;
384
384
- (void )unitTestSubscriptionPoolWorkComplete : (MTRDevice *)device ;
385
385
- (void )unitTestClusterDataPersisted : (MTRDevice *)device ;
386
+ - (BOOL )unitTestSuppressTimeBasedReachabilityChanges : (MTRDevice *)device ;
386
387
@end
387
388
#endif
388
389
@@ -2026,15 +2027,24 @@ - (void)_setupSubscriptionWithReason:(NSString *)reason
2026
2027
2027
2028
MTR_LOG (" %@ setting up subscription with reason: %@" , self, reason);
2028
2029
2029
- // Set up a timer to mark as not reachable if it takes too long to set up a subscription
2030
- MTRWeakReference<MTRDevice *> * weakSelf = [MTRWeakReference weakReferenceWithObject: self ];
2031
- dispatch_after (dispatch_time (DISPATCH_TIME_NOW, static_cast <int64_t >(kSecondsToWaitBeforeMarkingUnreachableAfterSettingUpSubscription ) * static_cast <int64_t >(NSEC_PER_SEC)), self.queue , ^{
2032
- MTRDevice * strongSelf = weakSelf.strongObject ;
2033
- if (strongSelf != nil ) {
2034
- std::lock_guard lock (strongSelf->_lock );
2035
- [strongSelf _markDeviceAsUnreachableIfNeverSubscribed ];
2036
- }
2037
- });
2030
+ bool markUnreachableAfterWait = true ;
2031
+ #ifdef DEBUG
2032
+ if (delegate && [delegate respondsToSelector: @selector (unitTestSuppressTimeBasedReachabilityChanges: )]) {
2033
+ markUnreachableAfterWait = ![delegate unitTestSuppressTimeBasedReachabilityChanges: self ];
2034
+ }
2035
+ #endif
2036
+
2037
+ if (markUnreachableAfterWait) {
2038
+ // Set up a timer to mark as not reachable if it takes too long to set up a subscription
2039
+ MTRWeakReference<MTRDevice *> * weakSelf = [MTRWeakReference weakReferenceWithObject: self ];
2040
+ dispatch_after (dispatch_time (DISPATCH_TIME_NOW, static_cast <int64_t >(kSecondsToWaitBeforeMarkingUnreachableAfterSettingUpSubscription ) * static_cast <int64_t >(NSEC_PER_SEC)), self.queue , ^{
2041
+ MTRDevice * strongSelf = weakSelf.strongObject ;
2042
+ if (strongSelf != nil ) {
2043
+ std::lock_guard lock (strongSelf->_lock );
2044
+ [strongSelf _markDeviceAsUnreachableIfNeverSubscribed ];
2045
+ }
2046
+ });
2047
+ }
2038
2048
2039
2049
[_deviceController
2040
2050
getSessionForNode: _nodeID.unsignedLongLongValue
0 commit comments