Skip to content

Commit

Permalink
Merge pull request AFNetworking#3694 from 0xced/fix-reachability-tests
Browse files Browse the repository at this point in the history
Fix reachability tests
  • Loading branch information
kcharwood authored Oct 12, 2016
2 parents 9627d0f + fb5022c commit 5b6def1
Showing 1 changed file with 16 additions and 28 deletions.
44 changes: 16 additions & 28 deletions Tests/Tests/AFNetworkReachabilityManagerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,9 @@ - (void)verifyReachabilityNotificationGetsPostedWithManager:(AFNetworkReachabili
handler:^BOOL(NSNotification *note) {
AFNetworkReachabilityStatus status;
status = [note.userInfo[AFNetworkingReachabilityNotificationStatusItem] integerValue];
BOOL reachable = (status == AFNetworkReachabilityStatusReachableViaWiFi
|| status == AFNetworkReachabilityStatusReachableViaWWAN);

if (reachable) {
XCTAssert(reachable,
@"Expected network to be reachable but got '%@'",
AFStringFromNetworkReachabilityStatus(status));
XCTAssertEqual(reachable, manager.isReachable, @"Expected status to match 'isReachable'");
}

return reachable;
BOOL isReachable = (status == AFNetworkReachabilityStatusReachableViaWiFi
|| status == AFNetworkReachabilityStatusReachableViaWWAN);
return isReachable;
}];

[manager startMonitoring];
Expand All @@ -86,24 +78,21 @@ - (void)testAddressReachabilityNotification {
[self verifyReachabilityNotificationGetsPostedWithManager:self.addressReachability];
}

//Commenting out for Travis Stability
//- (void)testDomainReachabilityNotification {
// [self verifyReachabilityNotificationGetsPostedWithManager:self.domainReachability];
//}
- (void)testDomainReachabilityNotification {
[self verifyReachabilityNotificationGetsPostedWithManager:self.domainReachability];
}

- (void)verifyReachabilityStatusBlockGetsCalledWithManager:(AFNetworkReachabilityManager *)manager
{
__weak 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) {
BOOL reachable = (status == AFNetworkReachabilityStatusReachableViaWiFi
|| status == AFNetworkReachabilityStatusReachableViaWWAN);

XCTAssert(reachable, @"Expected network to be reachable but got '%@'", AFStringFromNetworkReachabilityStatus(status));
XCTAssertEqual(reachable, weakManager.isReachable, @"Expected status to match 'isReachable'");

[expectation fulfill];
BOOL isReachable = (status == AFNetworkReachabilityStatusReachableViaWiFi
|| status == AFNetworkReachabilityStatusReachableViaWWAN);
if (isReachable) {
[expectation fulfill];
expectation = nil;
}
}];

[manager startMonitoring];
Expand All @@ -117,9 +106,8 @@ - (void)testAddressReachabilityBlock {
[self verifyReachabilityStatusBlockGetsCalledWithManager:self.addressReachability];
}

//Commenting out for Travis Stability
//- (void)testDomainReachabilityBlock {
// [self verifyReachabilityStatusBlockGetsCalledWithManager:self.domainReachability];
//}
- (void)testDomainReachabilityBlock {
[self verifyReachabilityStatusBlockGetsCalledWithManager:self.domainReachability];
}

@end

0 comments on commit 5b6def1

Please sign in to comment.