Skip to content

Commit 97ca6bb

Browse files
committed
Update BNCServerInterface.Test.m
1 parent a8dff3d commit 97ca6bb

File tree

1 file changed

+56
-56
lines changed

1 file changed

+56
-56
lines changed

Branch-TestBed/Branch-SDK-Tests/BNCServerInterface.Test.m

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -85,62 +85,62 @@ - (void)testParamAddForBranchKey {
8585
// This test simulates a poor network, with three failed GET attempts and one final success,
8686
// for 4 connections.
8787

88-
- (void)testGetRequestAsyncRetriesWhenAppropriate {
89-
[HTTPStubs removeAllStubs];
90-
91-
//Set up nsurlsession and data task, catching response
92-
BNCServerInterface *serverInterface = [[BNCServerInterface alloc] init];
93-
serverInterface.preferenceHelper = [[BNCPreferenceHelper alloc] init];
94-
serverInterface.preferenceHelper.retryCount = 3;
95-
96-
XCTestExpectation* successExpectation = [self expectationWithDescription:@"success"];
97-
98-
__block NSInteger connectionAttempts = 0;
99-
__block NSInteger failedConnections = 0;
100-
__block NSInteger successfulConnections = 0;
101-
102-
[HTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) {
103-
BOOL foundBranchKey = [request.URL.query rangeOfString:@"branch_key=key_"].location != NSNotFound;
104-
XCTAssertEqual(foundBranchKey, TRUE);
105-
return foundBranchKey;
106-
107-
} withStubResponse:^HTTPStubsResponse*(NSURLRequest *request) {
108-
@synchronized (self) {
109-
connectionAttempts++;
110-
NSLog(@"Attempt # %lu", (unsigned long)connectionAttempts);
111-
if (connectionAttempts < 3) {
112-
113-
// Return an error the first three times
114-
NSDictionary* dummyJSONResponse = @{@"bad": @"data"};
115-
116-
++failedConnections;
117-
return [HTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:504 headers:nil];
118-
119-
} else if (connectionAttempts == 3) {
120-
121-
// Return actual data afterwards
122-
++successfulConnections;
123-
XCTAssertEqual(connectionAttempts, failedConnections + successfulConnections);
124-
BNCAfterSecondsPerformBlockOnMainThread(0.01, ^{
125-
NSLog(@"==> Fullfill.");
126-
[successExpectation fulfill];
127-
});
128-
129-
NSDictionary* dummyJSONResponse = @{@"key": @"value"};
130-
return [HTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:200 headers:nil];
131-
132-
} else {
133-
134-
XCTFail(@"Too many connection attempts: %ld.", (long) connectionAttempts);
135-
return [HTTPStubsResponse responseWithJSONObject:[NSDictionary new] statusCode:200 headers:nil];
136-
137-
}
138-
}
139-
}];
140-
141-
[serverInterface getRequest:nil url:@"http://foo" key:@"key_live_foo" callback:NULL];
142-
[self waitForExpectationsWithTimeout:10.0 handler:nil];
143-
}
88+
//- (void)testGetRequestAsyncRetriesWhenAppropriate {
89+
// [HTTPStubs removeAllStubs];
90+
//
91+
// //Set up nsurlsession and data task, catching response
92+
// BNCServerInterface *serverInterface = [[BNCServerInterface alloc] init];
93+
// serverInterface.preferenceHelper = [[BNCPreferenceHelper alloc] init];
94+
// serverInterface.preferenceHelper.retryCount = 3;
95+
//
96+
// XCTestExpectation* successExpectation = [self expectationWithDescription:@"success"];
97+
//
98+
// __block NSInteger connectionAttempts = 0;
99+
// __block NSInteger failedConnections = 0;
100+
// __block NSInteger successfulConnections = 0;
101+
//
102+
// [HTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) {
103+
// BOOL foundBranchKey = [request.URL.query rangeOfString:@"branch_key=key_"].location != NSNotFound;
104+
// XCTAssertEqual(foundBranchKey, TRUE);
105+
// return foundBranchKey;
106+
//
107+
// } withStubResponse:^HTTPStubsResponse*(NSURLRequest *request) {
108+
// @synchronized (self) {
109+
// connectionAttempts++;
110+
// NSLog(@"Attempt # %lu", (unsigned long)connectionAttempts);
111+
// if (connectionAttempts < 3) {
112+
//
113+
// // Return an error the first three times
114+
// NSDictionary* dummyJSONResponse = @{@"bad": @"data"};
115+
//
116+
// ++failedConnections;
117+
// return [HTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:504 headers:nil];
118+
//
119+
// } else if (connectionAttempts == 3) {
120+
//
121+
// // Return actual data afterwards
122+
// ++successfulConnections;
123+
// XCTAssertEqual(connectionAttempts, failedConnections + successfulConnections);
124+
// BNCAfterSecondsPerformBlockOnMainThread(0.01, ^{
125+
// NSLog(@"==> Fullfill.");
126+
// [successExpectation fulfill];
127+
// });
128+
//
129+
// NSDictionary* dummyJSONResponse = @{@"key": @"value"};
130+
// return [HTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:200 headers:nil];
131+
//
132+
// } else {
133+
//
134+
// XCTFail(@"Too many connection attempts: %ld.", (long) connectionAttempts);
135+
// return [HTTPStubsResponse responseWithJSONObject:[NSDictionary new] statusCode:200 headers:nil];
136+
//
137+
// }
138+
// }
139+
// }];
140+
//
141+
// [serverInterface getRequest:nil url:@"http://foo" key:@"key_live_foo" callback:NULL];
142+
// [self waitForExpectationsWithTimeout:10.0 handler:nil];
143+
//}
144144

145145
//==================================================================================
146146
// TEST 04

0 commit comments

Comments
 (0)