aboutsummaryrefslogtreecommitdiff
path: root/src/net/http
diff options
context:
space:
mode:
authorZeke Lu <lvzecai@gmail.com>2022-10-31 17:18:32 +0000
committerDamien Neil <dneil@google.com>2022-10-31 20:44:00 +0000
commite943dc5a8ccab90286d3882e5d13e9fa9516f243 (patch)
tree55f584ebef87a2a5c0b4b930d02ce97a0214068f /src/net/http
parent6695cebeec02c62bd440eec8e982028225984dfb (diff)
downloadgo-e943dc5a8ccab90286d3882e5d13e9fa9516f243.tar.xz
net/http: deflake TestCancelRequestWhenSharingConnection
The test sleeps for 1 millisecond to give the cancellation a moment to take effect. This is flaky because the request can finish before the cancellation of the context is seen. It's easy to verify by adding time.Sleep(2*time.Millisecond) after https://github.com/golang/go/blob/0a6c4c87404ecb018faf002919e5d5db04c69ee2/src/net/http/transport.go#L2619. With this modification, the test fails about 5 times out of 10 runs. The fix is easy. We just need to block the handler of the second request until this request is cancelled. I have verify that the updated test can uncover the issue fixed by CL 257818. Fixes #55226. Change-Id: I81575beef1a920a2ffaa5c6a5ca70a4008bd5f94 GitHub-Last-Rev: 99cb1c2eaed7839394adbb6bbcd4950cd4bfb6f3 GitHub-Pull-Request: golang/go#56500 Reviewed-on: https://go-review.googlesource.com/c/go/+/446676 Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Bryan Mills <bcmills@google.com>
Diffstat (limited to 'src/net/http')
-rw-r--r--src/net/http/transport_test.go7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/net/http/transport_test.go b/src/net/http/transport_test.go
index cd31141e52..a581845516 100644
--- a/src/net/http/transport_test.go
+++ b/src/net/http/transport_test.go
@@ -6530,6 +6530,9 @@ func testCancelRequestWhenSharingConnection(t *testing.T, mode testMode) {
if !errors.Is(err, context.Canceled) {
t.Errorf("request 2: got err %v, want Canceled", err)
}
+
+ // Unblock the first request.
+ close(idlec)
}()
// Wait for the second request to arrive at the server, and then cancel
@@ -6537,9 +6540,7 @@ func testCancelRequestWhenSharingConnection(t *testing.T, mode testMode) {
r2c := <-reqc
cancel()
- // Give the cancellation a moment to take effect, and then unblock the first request.
- time.Sleep(1 * time.Millisecond)
- close(idlec)
+ <-idlec
close(r2c)
wg.Wait()