diff options
author | Michael Fraenkel <michael.fraenkel@gmail.com> | 2021-04-14 18:35:49 -0600 |
---|---|---|
committer | Damien Neil <dneil@google.com> | 2021-04-15 16:09:16 +0000 |
commit | 5631c4b3bfd71aae7cbdd7f35f63de7f89639d1e (patch) | |
tree | 6a754f7c9a181cd7a1a17b00ede580ef02141855 /src/net/http/transport_test.go | |
parent | 1d20a362d0ca4898d77865e314ef6f73582daef0 (diff) | |
download | go-5631c4b3bfd71aae7cbdd7f35f63de7f89639d1e.tar.gz go-5631c4b3bfd71aae7cbdd7f35f63de7f89639d1e.zip |
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 <bcmills@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Trust: Damien Neil <dneil@google.com>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Diffstat (limited to 'src/net/http/transport_test.go')
-rw-r--r-- | src/net/http/transport_test.go | 14 |
1 files 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() |