Skip to content

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
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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;
}
Expand Down

0 comments on commit fb5022c

Please sign in to comment.