|
16 | 16 |
|
17 | 17 | #import <XCTest/XCTest.h>
|
18 | 18 | #import <OHHTTPStubs/OHHTTPStubs.h>
|
| 19 | +#import <OCMock/OCMock.h> |
19 | 20 | #import "OPTLYHTTPRequestManager.h"
|
20 | 21 | #import "OPTLYTestHelper.h"
|
21 | 22 |
|
@@ -161,6 +162,33 @@ - (void)testPOSTWithParametersFailure
|
161 | 162 | }];
|
162 | 163 | }
|
163 | 164 |
|
| 165 | +- (void)testPOSTWithException |
| 166 | +{ |
| 167 | + |
| 168 | + |
| 169 | + [self swizzleConfig]; |
| 170 | + |
| 171 | + OPTLYHTTPRequestManager *requestManager = [OPTLYHTTPRequestManager new]; |
| 172 | + |
| 173 | + XCTestExpectation *expectation = [self expectationWithDescription:@"Wait for POSTWithParameters to timeout."]; |
| 174 | + // we are not expecting this to be filled. the session should just disappear. |
| 175 | + expectation.inverted = true; |
| 176 | + |
| 177 | + [requestManager POSTWithParameters:self.parameters url:self.testURL completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { |
| 178 | + // we never get here |
| 179 | + [expectation fulfill]; |
| 180 | + }]; |
| 181 | + |
| 182 | + [self waitForExpectationsWithTimeout:5.0 handler:^(NSError *error) { |
| 183 | + if (error) { |
| 184 | + NSLog(@"Error Occurred: %@", error); |
| 185 | + XCTAssert(false); |
| 186 | + } |
| 187 | + XCTAssert(true); |
| 188 | + [self swizzleConfig]; |
| 189 | + }]; |
| 190 | +} |
| 191 | + |
164 | 192 | // Tests the following for the POST with backoff retry:
|
165 | 193 | // 1. correct number of recursive calls
|
166 | 194 | // 2. the right delays are set at each retry attempt
|
@@ -350,4 +378,20 @@ - (void)checkMaxRetries:(OPTLYHTTPRequestManager *)requestManager {
|
350 | 378 | XCTAssertTrue(requestManager.retryAttemptTest == kRetryAttempts+1, @"Invalid number of retries.");
|
351 | 379 | XCTAssertTrue([requestManager.delaysTest isEqualToArray:self.expectedDelays], @"Invalid delays set for backoff retry.");
|
352 | 380 | }
|
| 381 | +- (void)swizzleConfig { |
| 382 | + Method method = class_getClassMethod(NSURLSessionConfiguration.class, @selector(ephemeralSessionConfiguration)); |
| 383 | + Method swizzle_method = class_getClassMethod(NSURLSessionConfiguration.class, @selector(getEphemeral)); |
| 384 | + |
| 385 | + method_exchangeImplementations(method, swizzle_method); |
| 386 | +} |
| 387 | +@end |
| 388 | + |
| 389 | +@interface NSURLSessionConfiguration(OPTLYSTubs) |
| 390 | + + (NSURLSessionConfiguration *)getEphemeral; |
| 391 | +@end |
| 392 | +@implementation NSURLSessionConfiguration(OPTLYSTubs) |
| 393 | + + (NSURLSessionConfiguration *)getEphemeral { |
| 394 | + [NSException raise:@"problem" format:@"problem"]; |
| 395 | + return nil; |
| 396 | + } |
353 | 397 | @end
|
0 commit comments