802802 address = ND. join_host_port (" 127.0.0.1" , Int (laddr. port))
803803 close_count = Ref (0 )
804804 stage = Ref (1 )
805+ second_chunk_started = Channel {Nothing} (1 )
806+ release_second_chunk = Channel {Nothing} (1 )
805807 callback_body = HT. CallbackBody (
806808 dst -> begin
807809 if stage[] == 1
811813 return length (bytes)
812814 end
813815 if stage[] == 2
814- sleep (1.0 )
816+ isready (second_chunk_started) || put! (second_chunk_started, nothing )
817+ take! (release_second_chunk)
815818 bytes = collect (codeunits (" world" ))
816819 copyto! (dst, 1 , bytes, 1 , length (bytes))
817820 stage[] = 3
@@ -837,15 +840,26 @@ end
837840 transport = HT. Transport (max_idle_per_host = 4 , max_idle_total = 4 )
838841 try
839842 req = HT. Request (" POST" , " /early" ; host = address, body = callback_body, content_length = 10 )
840- started = time ()
841- res = HT. roundtrip! (transport, address, req)
842- elapsed = time () - started
843- @test res. status == 200
844- @test String (_read_all_transport_body_bytes (res. body)) == " early"
845- @test elapsed < 0.75
846- @test timedwait (() -> close_count[] == 1 , 2.0 ; pollint = 0.001 ) != :timed_out
843+ res_task = errormonitor (Threads. @spawn HT. roundtrip! (transport, address, req))
844+ ready = timedwait (() -> istaskdone (res_task) || isready (second_chunk_started), 2.0 ; pollint = 0.001 )
845+ @test ready == :ok
846+ if ready == :ok && isready (second_chunk_started) && ! istaskdone (res_task)
847+ response_ready = timedwait (() -> istaskdone (res_task), 2.0 ; pollint = 0.001 )
848+ @test response_ready == :ok
849+ end
850+ @test istaskdone (res_task)
851+ isready (release_second_chunk) || put! (release_second_chunk, nothing )
852+ if istaskdone (res_task)
853+ res = fetch (res_task)
854+ @test res. status == 200
855+ @test String (_read_all_transport_body_bytes (res. body)) == " early"
856+ @test timedwait (() -> close_count[] == 1 , 2.0 ; pollint = 0.001 ) != :timed_out
857+ else
858+ _wait_task! (res_task)
859+ end
847860 _wait_task! (server_task)
848861 finally
862+ isready (release_second_chunk) || put! (release_second_chunk, nothing )
849863 close (transport)
850864 HTTP. @try_ignore NC. close (listener)
851865 end
0 commit comments