@@ -547,25 +547,71 @@ include("setup.jl")
547547 @test_skip " concurrent requests flakey on Windows"
548548 else
549549 mine = Downloader ()
550+
551+ delay = 2
552+ count = 100
553+ get_url = " $server /delay/$delay "
554+ post_url = " $server /post"
555+ post_data = " Hello, world!"
556+
557+ test_post_json = (downloader) -> begin
558+ _, json = request_json (post_url, input= IOBuffer (post_data), method= " POST" , downloader = downloader)
559+ @test json[" url" ] == post_url
560+ @test json[" data" ] == post_data
561+ end
562+
563+ test_get_json = (id, downloader) -> begin
564+ json = download_json (" $get_url ?id=$id " ; downloader)
565+ @test get (json[" args" ], " id" , nothing ) == [" $id " ]
566+ end
567+
568+ thread_count= Base. Threads. nthreads ()
569+ @info (" starting concurrent requests test" ,
570+ get_url= get_url,
571+ post_url= post_url,
572+ thread_count= thread_count,
573+ )
574+ # thread_options = (thread_count > 1 ? (false, true) : (true,))
575+ thread_options = (false , true )
576+
550577 for downloader in (nothing , mine)
551578 have_lsof = Sys. which (" lsof" ) != = nothing
552579 count_tcp () = Base. count (x-> contains (" TCP" ,x), split (read (` lsof -p $(getpid ()) ` , String), ' \n ' ))
553580 if have_lsof
554581 n_tcp = count_tcp ()
555582 end
556- delay = 2
557- count = 100
558- url = " $server /delay/$delay "
559- t = @elapsed @sync for id = 1 : count
560- @async begin
561- json = download_json (" $url ?id=$id " ; downloader)
562- @test get (json[" args" ], " id" , nothing ) == [" $id " ]
583+ for method in (:get , :post )
584+ for use_threads in thread_options
585+ @info (" concurrent requests test" ,
586+ is_default_downloader= (downloader === nothing ),
587+ method= method,
588+ use_threads= use_threads,
589+ )
590+ t = @elapsed @sync for id = 1 : count
591+ if use_threads
592+ Base. Threads. @spawn begin
593+ if method == :get
594+ test_get_json (id, downloader)
595+ else
596+ test_post_json (downloader)
597+ end
598+ end
599+ else
600+ @async begin
601+ if method == :get
602+ test_get_json (id, downloader)
603+ else
604+ test_post_json (downloader)
605+ end
606+ end
607+ end
608+ end
609+ @test t < 0.9 * count* delay
610+ if have_lsof
611+ @test n_tcp == count_tcp ()
612+ end
563613 end
564614 end
565- @test t < 0.9 * count* delay
566- if have_lsof
567- @test n_tcp == count_tcp ()
568- end
569615 end
570616 end
571617 end
0 commit comments