mirror of
https://github.com/golang/go
synced 2024-11-17 00:04:40 -07:00
net/http: improve errors in TestCancelRequestWhenSharingConnection
Provide more information about why this test might be hanging waiting for PutIdleConn to be called (#56587): If the round trip that should result in PutIdleConn being invoked completes, report that to the goroutine waiting for PutIdleConn. For #56587 Change-Id: Ie476ea0ce4a48d2bda6b9b109f89d675a10e7e45 Reviewed-on: https://go-review.googlesource.com/c/go/+/457775 Auto-Submit: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Damien Neil <dneil@google.com> Reviewed-by: Bryan Mills <bcmills@google.com>
This commit is contained in:
parent
24ac659a39
commit
f4b42f5cb8
@ -6565,7 +6565,8 @@ func testCancelRequestWhenSharingConnection(t *testing.T, mode testMode) {
|
||||
var wg sync.WaitGroup
|
||||
|
||||
wg.Add(1)
|
||||
putidlec := make(chan chan struct{})
|
||||
putidlec := make(chan chan struct{}, 1)
|
||||
reqerrc := make(chan error, 1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
ctx := httptrace.WithClientTrace(context.Background(), &httptrace.ClientTrace{
|
||||
@ -6574,24 +6575,31 @@ func testCancelRequestWhenSharingConnection(t *testing.T, mode testMode) {
|
||||
// and wait for the order to proceed.
|
||||
ch := make(chan struct{})
|
||||
putidlec <- ch
|
||||
close(putidlec) // panic if PutIdleConn runs twice for some reason
|
||||
<-ch
|
||||
},
|
||||
})
|
||||
req, _ := NewRequestWithContext(ctx, "GET", ts.URL, nil)
|
||||
res, err := client.Do(req)
|
||||
reqerrc <- err
|
||||
if err == nil {
|
||||
res.Body.Close()
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("request 1: got err %v, want nil", err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Wait for the first request to receive a response and return the
|
||||
// connection to the idle pool.
|
||||
r1c := <-reqc
|
||||
close(r1c)
|
||||
idlec := <-putidlec
|
||||
var idlec chan struct{}
|
||||
select {
|
||||
case err := <-reqerrc:
|
||||
if err != nil {
|
||||
t.Fatalf("request 1: got err %v, want nil", err)
|
||||
}
|
||||
idlec = <-putidlec
|
||||
case idlec = <-putidlec:
|
||||
}
|
||||
|
||||
wg.Add(1)
|
||||
cancelctx, cancel := context.WithCancel(context.Background())
|
||||
|
Loading…
Reference in New Issue
Block a user