aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Neil <dneil@google.com>2022-12-14 15:49:58 -0800
committerGopher Robot <gobot@golang.org>2022-12-16 17:12:28 +0000
commitf4b42f5cb8b494a2b64a4ade89f89071d80c7fd3 (patch)
tree4402a58c25ec872e882182a61040e3325b47cbcd
parent24ac659a395b2ef6c3877e82de15bed8e13fa40a (diff)
downloadgo-f4b42f5cb8b494a2b64a4ade89f89071d80c7fd3.tar.gz
go-f4b42f5cb8b494a2b64a4ade89f89071d80c7fd3.zip
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>
-rw-r--r--src/net/http/transport_test.go18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/net/http/transport_test.go b/src/net/http/transport_test.go
index 2bc83fd42b..245f73bc9f 100644
--- a/src/net/http/transport_test.go
+++ b/src/net/http/transport_test.go
@@ -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())