@@ -1165,32 +1165,34 @@ class TestURLSession: LoopbackServerTest {
1165
1165
}
1166
1166
1167
1167
1168
- func test_concurrentRequests( ) {
1169
- // "10 tasks ought to be enough for anybody"
1168
+ func test_concurrentRequests( ) throws {
1170
1169
let tasks = 10
1171
1170
let syncQ = dispatchQueueMake ( " test_dataTaskWithURL.syncQ " )
1172
1171
var dataTasks : [ DataTask ] = [ ]
1172
+ dataTasks. reserveCapacity ( tasks)
1173
+
1174
+ let urlString = " http://127.0.0.1: \( TestURLSession . serverPort) /Nepal "
1175
+ let url = try XCTUnwrap ( URL ( string: urlString) )
1176
+
1173
1177
let g = dispatchGroupMake ( )
1174
1178
for f in 0 ..< tasks {
1175
1179
g. enter ( )
1176
- let urlString = " http://127.0.0.1: \( TestURLSession . serverPort) /Nepal "
1177
1180
let expectation = self . expectation ( description: " GET \( urlString) [ \( f) ]: with a delegate " )
1178
1181
globalDispatchQueue. async {
1179
- let url = URL ( string: urlString) !
1180
1182
let d = DataTask ( with: expectation)
1181
1183
d. run ( with: url)
1182
- syncQ. async {
1184
+ syncQ. sync {
1183
1185
dataTasks. append ( d)
1184
- g. leave ( )
1185
1186
}
1187
+ g. leave ( )
1186
1188
}
1187
1189
}
1188
1190
waitForExpectations ( timeout: 12 )
1189
- g. wait ( )
1190
- for d in syncQ . sync ( execute : { dataTasks} ) {
1191
- if !d . error {
1192
- XCTAssertEqual ( d . capital , " Kathmandu " , " test_dataTaskWithURLRequest returned an unexpected result " )
1193
- }
1191
+ XCTAssertEqual ( g. wait ( timeout : . now ( ) + . milliseconds ( 1 ) ) , . success )
1192
+ XCTAssertEqual ( dataTasks. count , tasks )
1193
+ for task in dataTasks {
1194
+ XCTAssertFalse ( task . error )
1195
+ XCTAssertEqual ( task . capital , " Kathmandu " , " test_dataTaskWithURLRequest returned an unexpected result " )
1194
1196
}
1195
1197
}
1196
1198
@@ -1819,7 +1821,7 @@ class TestURLSession: LoopbackServerTest {
1819
1821
( " test_simpleUploadWithDelegate " , test_simpleUploadWithDelegate) ,
1820
1822
( " test_requestWithEmptyBody " , test_requestWithEmptyBody) ,
1821
1823
( " test_requestWithNonEmptyBody " , test_requestWithNonEmptyBody) ,
1822
- /* ⚠️ */ ( " test_concurrentRequests " , testExpectedToFail ( test_concurrentRequests, " Fails about 4% of the time " ) ) ,
1824
+ ( " test_concurrentRequests " , test_concurrentRequests) ,
1823
1825
( " test_disableCookiesStorage " , test_disableCookiesStorage) ,
1824
1826
( " test_cookiesStorage " , test_cookiesStorage) ,
1825
1827
( " test_cookieStorageForEphemeralConfiguration " , test_cookieStorageForEphemeralConfiguration) ,
0 commit comments