mirror of
https://github.com/golang/go
synced 2024-11-26 04:07:59 -07:00
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>
This commit is contained in:
parent
1d20a362d0
commit
5631c4b3bf
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user