From: Michael Fraenkel Date: Thu, 15 Apr 2021 00:35:49 +0000 (-0600) Subject: net/http: allow multiple dials in TestTransportMaxConnsPerHost X-Git-Tag: go1.17beta1~624 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=5631c4b3bfd71aae7cbdd7f35f63de7f89639d1e;p=gostls13.git net/http: allow multiple dials in TestTransportMaxConnsPerHost If there is more than the expected single dial, the channel will block. Allow at least one connection per client, and do the expected cleanup. Updates #45570 Change-Id: Iaecd45298a7d7c591b7d7b1be13cea6e4a1e2e85 Reviewed-on: https://go-review.googlesource.com/c/go/+/310213 Reviewed-by: Bryan C. Mills Reviewed-by: Damien Neil Trust: Damien Neil Trust: Emmanuel Odeke --- diff --git a/src/net/http/transport_test.go b/src/net/http/transport_test.go index 7f6e0938c2..5b6a5aa992 100644 --- a/src/net/http/transport_test.go +++ b/src/net/http/transport_test.go @@ -626,12 +626,15 @@ func TestTransportMaxConnsPerHost(t *testing.T) { t.Fatalf("ExportHttp2ConfigureTransport: %v", err) } - connCh := make(chan net.Conn, 1) + mu := sync.Mutex{} + var conns []net.Conn var dialCnt, gotConnCnt, tlsHandshakeCnt int32 tr.Dial = func(network, addr string) (net.Conn, error) { atomic.AddInt32(&dialCnt, 1) c, err := net.Dial(network, addr) - connCh <- c + mu.Lock() + defer mu.Unlock() + conns = append(conns, c) return c, err } @@ -685,7 +688,12 @@ func TestTransportMaxConnsPerHost(t *testing.T) { t.FailNow() } - (<-connCh).Close() + mu.Lock() + for _, c := range conns { + c.Close() + } + conns = nil + mu.Unlock() tr.CloseIdleConnections() doReq()