diff options
author | Damien Neil <dneil@google.com> | 2023-04-07 10:04:42 -0700 |
---|---|---|
committer | Damien Neil <dneil@google.com> | 2023-04-07 18:08:14 +0000 |
commit | 1444c0b01e4f83a90f0d97b3bf0b346290ec02e3 (patch) | |
tree | 061deec5888e005a3418755ca6baa2a738706012 /src/net/http/transport_test.go | |
parent | 38dadcc3b5e0f0ed70d224f1eb519a83dcdb52de (diff) | |
download | go-1444c0b01e4f83a90f0d97b3bf0b346290ec02e3.tar.gz go-1444c0b01e4f83a90f0d97b3bf0b346290ec02e3.zip |
net/http: wait forever for write results in tests
After performing a round trip on a connection, the connection is
usually returned to the idle connection pool. If the write of the
request did not complete successfully, the connection is not
returned.
It is possible for the response to be read before the write
goroutine has finished signalling that its write has completed.
To allow for this, the check to see if the write completed successfully
waits for 50ms for the write goroutine to report the result of the
write.
See comments in persistConn.wroteRequest for more details.
On a slow builder, it is possible for the write goroutine to take
longer than 50ms to report the status of its write, leading to test
flakiness when successive requests unexpectedly use different connections.
Set the timeout for waiting for the writer to an effectively
infinite duration in tests.
Fixes #51147
Fixes #56275
Fixes #56419
Fixes #56577
Fixes #57375
Fixes #57417
Fixes #57476
Fixes #57604
Fixes #57605
Change-Id: I5e92ffd66b676f3f976d8832c0910f27456a6991
Reviewed-on: https://go-review.googlesource.com/c/go/+/483116
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Diffstat (limited to 'src/net/http/transport_test.go')
-rw-r--r-- | src/net/http/transport_test.go | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/net/http/transport_test.go b/src/net/http/transport_test.go index 268b0a4776..6f57629eff 100644 --- a/src/net/http/transport_test.go +++ b/src/net/http/transport_test.go @@ -3402,9 +3402,13 @@ func (c byteFromChanReader) Read(p []byte) (n int, err error) { // questionable state. // golang.org/issue/7569 func TestTransportNoReuseAfterEarlyResponse(t *testing.T) { - run(t, testTransportNoReuseAfterEarlyResponse, []testMode{http1Mode}) + run(t, testTransportNoReuseAfterEarlyResponse, []testMode{http1Mode}, testNotParallel) } func testTransportNoReuseAfterEarlyResponse(t *testing.T, mode testMode) { + defer func(d time.Duration) { + *MaxWriteWaitBeforeConnReuse = d + }(*MaxWriteWaitBeforeConnReuse) + *MaxWriteWaitBeforeConnReuse = 10 * time.Millisecond var sconn struct { sync.Mutex c net.Conn @@ -3631,13 +3635,13 @@ func testRetryRequestsOnError(t *testing.T, mode testMode) { req := tc.req() res, err := c.Do(req) if err != nil { - if time.Since(t0) < MaxWriteWaitBeforeConnReuse/2 { + if time.Since(t0) < *MaxWriteWaitBeforeConnReuse/2 { mu.Lock() got := logbuf.String() mu.Unlock() t.Fatalf("i=%d: Do = %v; log:\n%s", i, err, got) } - t.Skipf("connection likely wasn't recycled within %d, interfering with actual test; skipping", MaxWriteWaitBeforeConnReuse) + t.Skipf("connection likely wasn't recycled within %d, interfering with actual test; skipping", *MaxWriteWaitBeforeConnReuse) } res.Body.Close() if res.Request != req { |