@@ -41,6 +41,7 @@ class TestURLSession : LoopbackServerTest {
41
41
( " test_outOfRangeButCorrectlyFormattedHTTPCode " , test_outOfRangeButCorrectlyFormattedHTTPCode) ,
42
42
( " test_missingContentLengthButStillABody " , test_missingContentLengthButStillABody) ,
43
43
( " test_illegalHTTPServerResponses " , test_illegalHTTPServerResponses) ,
44
+ ( " test_dataTaskWithSharedDelegate " , test_dataTaskWithSharedDelegate) ,
44
45
]
45
46
}
46
47
@@ -429,8 +430,37 @@ class TestURLSession : LoopbackServerTest {
429
430
waitForExpectations ( timeout: 12 )
430
431
}
431
432
}
433
+
434
+ func test_dataTaskWithSharedDelegate( ) {
435
+ let sharedDelegate = SharedDelegate ( )
436
+ let urlString0 = " http://127.0.0.1: \( TestURLSession . serverPort) /Nepal "
437
+ let session = URLSession ( configuration: . default, delegate: sharedDelegate, delegateQueue: nil )
438
+
439
+ let dataRequest = URLRequest ( url: URL ( string: urlString0) !)
440
+ let dataTask = session. dataTask ( with: dataRequest)
441
+
442
+ sharedDelegate. dataCompletionExpectation = expectation ( description: " GET \( urlString0) " )
443
+ dataTask. resume ( )
444
+ waitForExpectations ( timeout: 20 )
445
+ }
432
446
}
433
447
448
+ class SharedDelegate : NSObject {
449
+ var dataCompletionExpectation : XCTestExpectation !
450
+ }
451
+
452
+ extension SharedDelegate : URLSessionDataDelegate {
453
+ func urlSession( _ session: URLSession , dataTask: URLSessionDataTask , didReceive data: Data ) {
454
+ dataCompletionExpectation. fulfill ( )
455
+ }
456
+ }
457
+
458
+ extension SharedDelegate : URLSessionDownloadDelegate {
459
+ func urlSession( _ session: URLSession , downloadTask: URLSessionDownloadTask , didFinishDownloadingTo location: URL ) {
460
+ }
461
+ }
462
+
463
+
434
464
class SessionDelegate : NSObject , URLSessionDelegate {
435
465
let invalidateExpectation : XCTestExpectation
436
466
init ( invalidateExpectation: XCTestExpectation ) {
0 commit comments