@@ -385,25 +385,64 @@ include("setup.jl")
385
385
@test_skip " concurrent requests flakey on Windows"
386
386
else
387
387
mine = Downloader ()
388
+
389
+ delay = 2
390
+ count = 100
391
+ get_url = " $server /delay/$delay "
392
+ post_url = " $server /post"
393
+ post_data = " Hello, world!"
394
+
395
+ test_post_json = (downloader) -> begin
396
+ _, json = request_json (post_url, input= IOBuffer (post_data), method= " POST" , downloader = downloader)
397
+ @test json[" url" ] == post_url
398
+ @test json[" data" ] == post_data
399
+ end
400
+
401
+ test_get_json = (id, downloader) -> begin
402
+ json = download_json (" $get_url ?id=$id " , downloader = downloader)
403
+ @test get (json[" args" ], " id" , nothing ) == [" $id " ]
404
+ end
405
+
388
406
for downloader in (nothing , mine)
389
407
have_lsof = Sys. which (" lsof" ) != = nothing
390
408
count_tcp () = Base. count (x-> contains (" TCP" ,x), split (read (` lsof -p $(getpid ()) ` , String), ' \n ' ))
391
409
if have_lsof
392
410
n_tcp = count_tcp ()
393
411
end
394
- delay = 2
395
- count = 100
396
- url = " $server /delay/$delay "
397
- t = @elapsed @sync for id = 1 : count
398
- @async begin
399
- json = download_json (" $url ?id=$id " , downloader = downloader)
400
- @test get (json[" args" ], " id" , nothing ) == [" $id " ]
412
+ for method in (:get , :post )
413
+ for use_threads in (false , true )
414
+ @info (" concurrent requests test" ,
415
+ is_default_downloader= (downloader === nothing ),
416
+ method= method,
417
+ get_url= get_url,
418
+ thread_count= Base. Threads. nthreads (),
419
+ use_threads= use_threads,
420
+ )
421
+ t = @elapsed @sync for id = 1 : count
422
+ if use_threads
423
+ Base. Threads. @spawn begin
424
+ if method == :get
425
+ test_get_json (id, downloader)
426
+ else
427
+ test_post_json (downloader)
428
+ end
429
+ end
430
+ else
431
+ @async begin
432
+ if method == :get
433
+ test_get_json (id, downloader)
434
+ else
435
+ test_post_json (downloader)
436
+ end
437
+ end
438
+ end
439
+ end
440
+ @test t < 0.9 * count* delay
441
+ if have_lsof
442
+ @test n_tcp == count_tcp ()
443
+ end
401
444
end
402
445
end
403
- @test t < 0.9 * count* delay
404
- if have_lsof
405
- @test n_tcp == count_tcp ()
406
- end
407
446
end
408
447
end
409
448
end
0 commit comments