@@ -37,8 +37,9 @@ class TestURLSession : XCTestCase {
37
37
( " test_verifyRequestHeaders " , test_verifyRequestHeaders) ,
38
38
( " test_verifyHttpAdditionalHeaders " , test_verifyHttpAdditionalHeaders) ,
39
39
( " test_timeoutInterval " , test_timeoutInterval) ,
40
- ( " test_customProtocol " , test_customProtocol) ,
41
- ( " test_httpRedirection " , test_httpRedirection) ,
40
+ ( " test_customProtocol " , test_customProtocol) ,
41
+ ( " test_httpRedirection " , test_httpRedirection) ,
42
+ ( " test_httpRedirectionTimeout " , test_httpRedirectionTimeout) ,
42
43
]
43
44
}
44
45
@@ -415,7 +416,7 @@ class TestURLSession : XCTestCase {
415
416
let serverReady = ServerSemaphore ( )
416
417
globalDispatchQueue. async {
417
418
do {
418
- try self . runServer ( with: serverReady, startDelay : 3 , sendDelay: 5 , bodyChunks: 3 )
419
+ try self . runServer ( with: serverReady, sendDelay: 5 , bodyChunks: 1 )
419
420
} catch {
420
421
XCTAssertTrue ( true )
421
422
return
@@ -485,6 +486,33 @@ class TestURLSession : XCTestCase {
485
486
d. run ( with: url)
486
487
waitForExpectations ( timeout: 12 )
487
488
}
489
+
490
+ func test_httpRedirectionTimeout( ) {
491
+ let serverReady = ServerSemaphore ( )
492
+ globalDispatchQueue. async {
493
+ do {
494
+ try self . runServer ( with: serverReady, sendDelay: 2 , bodyChunks: 1 )
495
+ } catch {
496
+ XCTAssertTrue ( true )
497
+ return
498
+ }
499
+ }
500
+ serverReady. wait ( )
501
+ var req = URLRequest ( url: URL ( string: " http://127.0.0.1: \( serverPort) /UnitedStates " ) !)
502
+ req. timeoutInterval = 3
503
+ let config = URLSessionConfiguration . default
504
+ var expect = expectation ( description: " download task with handler " )
505
+ let session = URLSession ( configuration: config, delegate: nil , delegateQueue: nil )
506
+ let task = session. dataTask ( with: req) { data, response, error in
507
+ defer { expect. fulfill ( ) }
508
+ if let e = error as? URLError {
509
+ XCTAssertEqual ( e. code, . timedOut, " Unexpected error code " )
510
+ return
511
+ }
512
+ }
513
+ task. resume ( )
514
+ waitForExpectations ( timeout: 12 )
515
+ }
488
516
}
489
517
490
518
class SessionDelegate : NSObject , URLSessionDelegate {
0 commit comments