From 5631c4b3bfd71aae7cbdd7f35f63de7f89639d1e Mon Sep 17 00:00:00 2001 From: Michael Fraenkel Date: Wed, 14 Apr 2021 18:35:49 -0600 Subject: [PATCH] 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 --- src/net/http/transport_test.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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() -- 2.50.0