Skip to content

Commit 6bf1982

Browse files
committed
Use distinct sessions for parallel loop tests to secure results
1 parent dd23bc5 commit 6bf1982

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

OHHTTPStubs/UnitTests/Test Suites/NSURLSessionTests.m

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -296,20 +296,20 @@ - (void)test_NSURLSessionDefaultConfig_notFollowingRedirects
296296
**/
297297
- (void)test_NSURLSessionDefaultConfig_MethodAndDataRetentionOnRedirect
298298
{
299-
NSURLSessionTestDelegate* delegate = [NSURLSessionTestDelegate delegateFollowingRedirects:YES fulfillOnCompletion:nil];
300-
301299
if ([NSURLSessionConfiguration class] && [NSURLSession class])
302300
{
303-
NSURLSessionConfiguration* config = [NSURLSessionConfiguration defaultSessionConfiguration];
304-
NSURLSession *session = [NSURLSession sessionWithConfiguration:config delegate:delegate delegateQueue:nil];
305-
306301
NSDictionary* json = @{ @"query": @"Hello World" };
307302
NSArray<NSString*>* allMethods = @[@"GET", @"HEAD", @"POST", @"PATCH", @"PUT"];
308303

309304
/** 301, 302, 307, 308: GET, HEAD, POST, PATCH, PUT should all maintain HTTP method and body unchanged **/
310305
for (NSNumber* redirectStatusCode in @[@301, @302, @307, @308]) {
311306
int statusCode = redirectStatusCode.intValue;
312307
for (NSString* method in allMethods) {
308+
309+
NSURLSessionConfiguration* config = [NSURLSessionConfiguration defaultSessionConfiguration];
310+
NSURLSessionTestDelegate* delegate = [NSURLSessionTestDelegate delegateFollowingRedirects:YES fulfillOnCompletion:nil];
311+
NSURLSession *session = [NSURLSession sessionWithConfiguration:config delegate:delegate delegateQueue:nil];
312+
313313
[self _test_redirect_NSURLSession:session httpMethod:method jsonBody:json delays:0.0 redirectStatusCode:statusCode
314314
completion:^(NSString *redirectedRequestMethod, id redirectedRequestJSONBody, NSHTTPURLResponse *redirectHTTPResponse, id finalJSONResponse, NSError *errorResponse)
315315
{
@@ -323,11 +323,18 @@ - (void)test_NSURLSessionDefaultConfig_MethodAndDataRetentionOnRedirect
323323
@"Unexpected JSON response received after %d redirect", statusCode);
324324
XCTAssertNil(errorResponse, @"Unexpected error during %d redirect", statusCode);
325325
}];
326+
327+
[session finishTasksAndInvalidate];
326328
}
327329
}
328330

329331
/** 303: GET, HEAD, POST, PATCH, PUT should use a GET HTTP method after redirection and not forward the body **/
330332
for (NSString* method in allMethods) {
333+
334+
NSURLSessionConfiguration* config = [NSURLSessionConfiguration defaultSessionConfiguration];
335+
NSURLSessionTestDelegate* delegate = [NSURLSessionTestDelegate delegateFollowingRedirects:YES fulfillOnCompletion:nil];
336+
NSURLSession *session = [NSURLSession sessionWithConfiguration:config delegate:delegate delegateQueue:nil];
337+
331338
[self _test_redirect_NSURLSession:session httpMethod:method jsonBody:json delays:0.0 redirectStatusCode:303
332339
completion:^(NSString *redirectedRequestMethod, id redirectedRequestJSONBody, NSHTTPURLResponse *redirectHTTPResponse, id finalJSONResponse, NSError *errorResponse)
333340
{
@@ -337,9 +344,9 @@ - (void)test_NSURLSessionDefaultConfig_MethodAndDataRetentionOnRedirect
337344
XCTAssertEqualObjects(finalJSONResponse, @{ @"RequestBody": json }, @"Unexpected JSON response received after 303 redirect");
338345
XCTAssertNil(errorResponse, @"Unexpected error during 303 redirect");
339346
}];
340-
}
341347

342-
[session finishTasksAndInvalidate];
348+
[session finishTasksAndInvalidate];
349+
}
343350
}
344351
else
345352
{

0 commit comments

Comments
 (0)