Permalink
Browse files

Remove assertion that status in callback == reachabilityManager status

The status passed in callbacks (both block and notification) is captured before the callbacks are dispatched on the main thread. It is thus possible that the reachabilityManager status change in the meantime.

Users MUST use the status parameter for the block callback or the `AFNetworkingReachabilityNotificationStatusItem` user info key for the notification.
1 parent 025c82f commit fb5022c0732e9be6981cf23bf04b9ef7ebd3e527 @0xced 0xced committed Oct 12, 2016
Showing with 6 additions and 13 deletions.
  1. +6 −13 Tests/Tests/AFNetworkReachabilityManagerTests.m
@@ -64,12 +64,9 @@ - (void)verifyReachabilityNotificationGetsPostedWithManager:(AFNetworkReachabili
handler:^BOOL(NSNotification *note) {
AFNetworkReachabilityStatus status;
status = [note.userInfo[AFNetworkingReachabilityNotificationStatusItem] integerValue];
- BOOL reachable = (status == AFNetworkReachabilityStatusReachableViaWiFi
- || status == AFNetworkReachabilityStatusReachableViaWWAN);
-
- XCTAssertEqual(reachable, manager.isReachable, @"Expected status to match 'isReachable'");
-
- return reachable;
+ BOOL isReachable = (status == AFNetworkReachabilityStatusReachableViaWiFi
+ || status == AFNetworkReachabilityStatusReachableViaWWAN);
+ return isReachable;
}];
[manager startMonitoring];
@@ -89,14 +86,10 @@ - (void)verifyReachabilityStatusBlockGetsCalledWithManager:(AFNetworkReachabilit
{
__weak __block XCTestExpectation *expectation = [self expectationWithDescription:@"reachability status change block gets called"];
- typeof(manager) __weak weakManager = manager;
[manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
- BOOL reachable = (status == AFNetworkReachabilityStatusReachableViaWiFi
- || status == AFNetworkReachabilityStatusReachableViaWWAN);
-
- XCTAssertEqual(reachable, weakManager.isReachable, @"Expected status to match 'isReachable'");
-
- if (reachable) {
+ BOOL isReachable = (status == AFNetworkReachabilityStatusReachableViaWiFi
+ || status == AFNetworkReachabilityStatusReachableViaWWAN);
+ if (isReachable) {
[expectation fulfill];
expectation = nil;
}

0 comments on commit fb5022c

Please sign in to comment.