File tree Expand file tree Collapse file tree 3 files changed +42
-1
lines changed
Tests/SentryTests/Networking Expand file tree Collapse file tree 3 files changed +42
-1
lines changed Original file line number Diff line number Diff line change 4444void
4545SentrySetReachabilityIgnoreActualCallback (BOOL value)
4646{
47+ SENTRY_LOG_DEBUG (@" Setting ignore actual callback to %@ " , value ? @" YES" : @" NO" );
4748 sentry_reachability_ignore_actual_callback = value;
4849}
4950
@@ -155,6 +156,15 @@ + (void)initialize
155156 }
156157}
157158
159+ - (instancetype )init
160+ {
161+ if (self = [super init ]) {
162+ self.skipRegisteringActualCallbacks = NO ;
163+ }
164+
165+ return self;
166+ }
167+
158168- (void )addObserver : (id <SentryReachabilityObserver>)observer ;
159169{
160170 SENTRY_LOG_DEBUG (@" Adding observer: %@ " , observer);
@@ -171,6 +181,11 @@ - (void)addObserver:(id<SentryReachabilityObserver>)observer;
171181 return ;
172182 }
173183
184+ if (self.skipRegisteringActualCallbacks ) {
185+ SENTRY_LOG_DEBUG (@" Skip registering actual callbacks" );
186+ return ;
187+ }
188+
174189 sentry_reachability_queue
175190 = dispatch_queue_create (" io.sentry.cocoa.connectivity" , DISPATCH_QUEUE_SERIAL);
176191 // Ensure to call CFRelease for the return value of SCNetworkReachabilityCreateWithName, see
@@ -214,6 +229,10 @@ - (void)removeAllObservers
214229
215230- (void )unsetReachabilityCallback
216231{
232+ if (self.skipRegisteringActualCallbacks ) {
233+ SENTRY_LOG_DEBUG (@" Skip unsetting actual callbacks" );
234+ }
235+
217236 sentry_current_reachability_state = kSCNetworkReachabilityFlagsUninitialized ;
218237
219238 if (_sentry_reachability_ref != nil ) {
Original file line number Diff line number Diff line change @@ -65,6 +65,12 @@ SENTRY_EXTERN NSString *const SentryConnectivityNone;
6565 */
6666@interface SentryReachability : NSObject
6767
68+ /* *
69+ * Only needed for testing. Use this flag to skip registering and unregistering the actual callbacks
70+ * to SCNetworkReachability to minimize side effects.
71+ */
72+ @property (nonatomic , assign ) BOOL skipRegisteringActualCallbacks;
73+
6874/* *
6975 * Add an observer which is called each time network connectivity changes.
7076 */
Original file line number Diff line number Diff line change @@ -35,11 +35,13 @@ @implementation SentryReachabilityTest
3535
3636- (void )setUp
3737{
38- self.reachability = [[SentryReachability alloc ] init ];
3938 // Ignore the actual reachability callbacks, cause we call the callbacks manually.
4039 // Otherwise, the actual reachability callbacks are called during later unrelated tests causing
4140 // flakes.
4241 SentrySetReachabilityIgnoreActualCallback (YES );
42+
43+ self.reachability = [[SentryReachability alloc ] init ];
44+ self.reachability .skipRegisteringActualCallbacks = YES ;
4345}
4446
4547- (void )tearDown
@@ -145,5 +147,19 @@ - (void)testReportSameReachabilityState_OnlyCalledOnce
145147 [self .reachability removeObserver: observer];
146148}
147149
150+ /* *
151+ * We only want to make sure running the actual registering and unregistering callbacks doesn't
152+ * crash.
153+ */
154+ - (void )testRegisteringActualCallbacks
155+ {
156+ self.reachability .skipRegisteringActualCallbacks = NO ;
157+
158+ TestSentryReachabilityObserver *observer = [[TestSentryReachabilityObserver alloc ] init ];
159+
160+ [self .reachability addObserver: observer];
161+ [self .reachability removeObserver: observer];
162+ }
163+
148164@end
149165#endif // !TARGET_OS_WATCH
You can’t perform that action at this time.
0 commit comments