@@ -376,6 +376,7 @@ - (BOOL)unitTestPretendThreadEnabled:(MTRDevice *)device;
376
376
- (void )unitTestSubscriptionPoolDequeue : (MTRDevice *)device ;
377
377
- (void )unitTestSubscriptionPoolWorkComplete : (MTRDevice *)device ;
378
378
- (void )unitTestClusterDataPersisted : (MTRDevice *)device ;
379
+ - (BOOL )unitTestSuppressTimeBasedReachabilityChanges : (MTRDevice *)device ;
379
380
@end
380
381
#endif
381
382
@@ -2014,15 +2015,24 @@ - (void)_setupSubscriptionWithReason:(NSString *)reason
2014
2015
2015
2016
MTR_LOG (" %@ setting up subscription with reason: %@" , self, reason);
2016
2017
2017
- // Set up a timer to mark as not reachable if it takes too long to set up a subscription
2018
- MTRWeakReference<MTRDevice *> * weakSelf = [MTRWeakReference weakReferenceWithObject: self ];
2019
- dispatch_after (dispatch_time (DISPATCH_TIME_NOW, static_cast <int64_t >(kSecondsToWaitBeforeMarkingUnreachableAfterSettingUpSubscription ) * static_cast <int64_t >(NSEC_PER_SEC)), self.queue , ^{
2020
- MTRDevice * strongSelf = weakSelf.strongObject ;
2021
- if (strongSelf != nil ) {
2022
- std::lock_guard lock (strongSelf->_lock );
2023
- [strongSelf _markDeviceAsUnreachableIfNeverSubscribed ];
2024
- }
2025
- });
2018
+ bool markUnreachableAfterWait = true ;
2019
+ #ifdef DEBUG
2020
+ if (delegate && [delegate respondsToSelector: @selector (unitTestSuppressTimeBasedReachabilityChanges: )]) {
2021
+ markUnreachableAfterWait = ![delegate unitTestSuppressTimeBasedReachabilityChanges: self ];
2022
+ }
2023
+ #endif
2024
+
2025
+ if (markUnreachableAfterWait) {
2026
+ // Set up a timer to mark as not reachable if it takes too long to set up a subscription
2027
+ MTRWeakReference<MTRDevice *> * weakSelf = [MTRWeakReference weakReferenceWithObject: self ];
2028
+ dispatch_after (dispatch_time (DISPATCH_TIME_NOW, static_cast <int64_t >(kSecondsToWaitBeforeMarkingUnreachableAfterSettingUpSubscription ) * static_cast <int64_t >(NSEC_PER_SEC)), self.queue , ^{
2029
+ MTRDevice * strongSelf = weakSelf.strongObject ;
2030
+ if (strongSelf != nil ) {
2031
+ std::lock_guard lock (strongSelf->_lock );
2032
+ [strongSelf _markDeviceAsUnreachableIfNeverSubscribed ];
2033
+ }
2034
+ });
2035
+ }
2026
2036
2027
2037
[_deviceController
2028
2038
getSessionForNode: _nodeID.unsignedLongLongValue
0 commit comments