]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: improve errors in TestCancelRequestWhenSharingConnection
authorDamien Neil <dneil@google.com>
Wed, 14 Dec 2022 23:49:58 +0000 (15:49 -0800)
committerGopher Robot <gobot@golang.org>
Fri, 16 Dec 2022 17:12:28 +0000 (17:12 +0000)
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>
src/net/http/transport_test.go

index 2bc83fd42b290e848b71b30e63b14f8d57ac69ac..245f73bc9fec42a21facd68ca139a0e54b9b232b 100644 (file)
@@ -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())