Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Remove assertion that status in callback == reachabilityManager status
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
0xced committed Oct 12, 2016
1 parent 025c82f commit fb5022c
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions Tests/Tests/AFNetworkReachabilityManagerTests.m
Expand Up @@ -64,12 +64,9 @@ - (void)verifyReachabilityNotificationGetsPostedWithManager:(AFNetworkReachabili
handler:^BOOL(NSNotification *note) { handler:^BOOL(NSNotification *note) {
AFNetworkReachabilityStatus status; AFNetworkReachabilityStatus status;
status = [note.userInfo[AFNetworkingReachabilityNotificationStatusItem] integerValue]; status = [note.userInfo[AFNetworkingReachabilityNotificationStatusItem] integerValue];
BOOL reachable = (status == AFNetworkReachabilityStatusReachableViaWiFi BOOL isReachable = (status == AFNetworkReachabilityStatusReachableViaWiFi
|| status == AFNetworkReachabilityStatusReachableViaWWAN); || status == AFNetworkReachabilityStatusReachableViaWWAN);

return isReachable;
XCTAssertEqual(reachable, manager.isReachable, @"Expected status to match 'isReachable'");

return reachable;
}]; }];


[manager startMonitoring]; [manager startMonitoring];
Expand All @@ -89,14 +86,10 @@ - (void)verifyReachabilityStatusBlockGetsCalledWithManager:(AFNetworkReachabilit
{ {
__weak __block XCTestExpectation *expectation = [self expectationWithDescription:@"reachability status change block gets called"]; __weak __block XCTestExpectation *expectation = [self expectationWithDescription:@"reachability status change block gets called"];


typeof(manager) __weak weakManager = manager;
[manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) { [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
BOOL reachable = (status == AFNetworkReachabilityStatusReachableViaWiFi BOOL isReachable = (status == AFNetworkReachabilityStatusReachableViaWiFi
|| status == AFNetworkReachabilityStatusReachableViaWWAN); || status == AFNetworkReachabilityStatusReachableViaWWAN);

if (isReachable) {
XCTAssertEqual(reachable, weakManager.isReachable, @"Expected status to match 'isReachable'");

if (reachable) {
[expectation fulfill]; [expectation fulfill];
expectation = nil; expectation = nil;
} }
Expand Down

0 comments on commit fb5022c

Please sign in to comment.