@@ -562,24 +562,24 @@ end
562562
563563@testset " HTTP CONNECT Proxy pool" begin
564564 function forwardclosetask (src, dst)
565- errormonitor ( @async begin
565+ @async begin
566566 forwardstream (src, dst)
567567 close (src)
568568 close (dst)
569- end )
569+ end
570570 end
571571
572572 # Stores the http message passed by the client
573- messages = []
574- upstreams = Set ()
573+ downstreamcount = 0
574+ upstreamsockets = Base . IdSet {TCPSocket} ()
575575
576576 # Simple implementation of a https proxy server
577577 proxy = HTTP. listen! (IPv4 (0 ), 8082 ; stream = true ) do http:: HTTP.Stream
578- push! (messages, http . message)
578+ downstreamcount += 1
579579
580580 hostport = split (http. message. target, " :" )
581581 targetstream = connect (hostport[1 ], parse (Int, get (hostport, 2 , " 443" )))
582- push! (upstreams , targetstream)
582+ push! (upstreamsockets , targetstream)
583583 try
584584 HTTP. setstatus (http, 200 )
585585 HTTP. startwrite (http)
@@ -589,25 +589,23 @@ end
589589 wait (up)
590590 wait (down)
591591 finally
592- delete! (upstreams , targetstream)
592+ delete! (upstreamsockets , targetstream)
593593 end
594594 end
595595
596596 try
597597 # Make the HTTP request
598598 r1 = HTTP. get (" https://$httpbin /ip" ; proxy= " http://localhost:8082" , retry= false , status_exception= true )
599- @test length (messages) == 1
600- @test first (messages). method == " CONNECT"
601- @test length (upstreams) == 1 && isopen (first (upstreams)) # still alive
599+ @test downstreamcount == 1
600+ @test length (upstreamsockets) == 1 && isopen (first (upstreamsockets)) # still alive
602601
603602 # Make another request
604603 # This should reuse the connection pool and not make another request to the proxy
605- empty! (messages)
606604 r2 = HTTP. get (" https://$httpbin /ip" ; proxy= " http://localhost:8082" , retry= false , status_exception= true )
607- @test isempty (messages) # no new message to the proxy
608- @test length (upstreams ) == 1 && isopen (first (upstreams )) # still only one stream alive
605+ @test downstreamcount == 1 # no new message to the proxy
606+ @test length (upstreamsockets ) == 1 && isopen (first (upstreamsockets )) # still only one stream alive
609607 finally
610- close .(upstreams )
608+ close .(upstreamsockets )
611609 close (proxy)
612610 HTTP. Connections. closeall ()
613611 wait (proxy)
@@ -616,20 +614,23 @@ end
616614
617615@testset " HTTP Proxy pool" begin
618616 # Stores the http request passed by the client
619- downstreamconnections = Set {HTTP.Connections.Connection} ()
620- upstreamconnections = Set {HTTP.Connections.Connection} ()
621- finished_request = Base. Event (true )
617+ downstreamconnections = Base. IdSet {HTTP.Connections.Connection} ()
618+ upstreamconnections = Base. IdSet {HTTP.Connections.Connection} ()
619+ downstreamcount = 0
620+ upstreamcount = 0
622621
623622 # Simple implementation of a http proxy server
624623 proxy = HTTP. listen! (IPv4 (0 ), 8082 ; stream = true ) do http:: HTTP.Stream
625624 push! (downstreamconnections, http. stream)
625+ downstreamcount += 1
626626
627627 HTTP. open (http. message. method, http. message. target, http. message. headers;
628628 decompress = false , version = http. message. version, retry= false ,
629629 redirect = false ) do targetstream
630630 push! (upstreamconnections, targetstream. stream)
631+ upstreamcount += 1
631632
632- up = errormonitor ( @async forwardstream (http, targetstream) )
633+ up = @async forwardstream (http, targetstream)
633634 targetresponse = startread (targetstream)
634635
635636 HTTP. setstatus (http, targetresponse. status)
@@ -638,30 +639,30 @@ end
638639 end
639640
640641 HTTP. startwrite (http)
641- down = errormonitor (@async forwardstream (targetstream, http))
642+ down = Base . errormonitor (@async forwardstream (targetstream, http))
642643
643644 wait (up)
644645 wait (down)
645-
646- notify (finished_request)
647646 end
648647 end
649648
650649 try
651650 # Make the HTTP request
652651 r1 = HTTP. get (" http://$httpbin /ip" ; proxy= " http://localhost:8082" , retry= false , redirect = false , status_exception= true )
653- wait (finished_request)
654652 @test length (downstreamconnections) == 1
655653 @test length (upstreamconnections) == 1
654+ @test downstreamcount == 1
655+ @test upstreamcount == 1
656656
657657 # Make another request
658658 # This should reuse a connection pool in both the client and proxy
659659 r2 = HTTP. get (" http://$httpbin /ip" ; proxy= " http://localhost:8082" , retry= false , redirect = false , status_exception= true )
660660
661- # Check that notify was actually called, but that the set of connections remains of size 1
662- wait (finished_request)
661+ # Check that the set of connections remains of size 1 when handling additional requests downstream and upstream
663662 @test length (downstreamconnections) == 1
664663 @test length (upstreamconnections) == 1
664+ @test downstreamcount == 2
665+ @test upstreamcount == 2
665666 finally
666667 close (proxy)
667668 HTTP. Connections. closeall ()
0 commit comments