]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: allow multiple dials in TestTransportMaxConnsPerHost
authorMichael Fraenkel <michael.fraenkel@gmail.com>
Thu, 15 Apr 2021 00:35:49 +0000 (18:35 -0600)
committerDamien Neil <dneil@google.com>
Thu, 15 Apr 2021 16:09:16 +0000 (16:09 +0000)
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>

src/net/http/transport_test.go

index 7f6e0938c20fa92276120d51fdc8189e1afd7cd2..5b6a5aa992557d664b65580574799ec38d31ccec 100644 (file)
@@ -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()