diff options
author | Brad Fitzpatrick <bradfitz@golang.org> | 2019-05-25 18:47:22 +0000 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2019-05-28 00:54:10 +0000 |
commit | 3970667d958eadbe591400ac9a53051a39f40ea2 (patch) | |
tree | 08d3758a155fb9427cda21bc0cb31daab19734d2 /src/net/http/transport_test.go | |
parent | f736de04aa52d4889760ecfe4380da01aaf4758f (diff) | |
download | go-3970667d958eadbe591400ac9a53051a39f40ea2.tar.gz go-3970667d958eadbe591400ac9a53051a39f40ea2.zip |
net/http: fix TestTransportServerClosingUnexpectedly flake
Fixes #32119
Change-Id: I8cf2e2e69737e2485568af91ab75149f3cf66781
Reviewed-on: https://go-review.googlesource.com/c/go/+/178918
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/net/http/transport_test.go')
-rw-r--r-- | src/net/http/transport_test.go | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/net/http/transport_test.go b/src/net/http/transport_test.go index 9de2fdab66..21d26a24b2 100644 --- a/src/net/http/transport_test.go +++ b/src/net/http/transport_test.go @@ -737,6 +737,8 @@ func TestTransportRemovesDeadIdleConnections(t *testing.T) { } } +// Test that the Transport notices when a server hangs up on its +// unexpectedly (a keep-alive connection is closed). func TestTransportServerClosingUnexpectedly(t *testing.T) { setParallel(t) defer afterTest(t) @@ -773,13 +775,14 @@ func TestTransportServerClosingUnexpectedly(t *testing.T) { body1 := fetch(1, 0) body2 := fetch(2, 0) - ts.CloseClientConnections() // surprise! - - // This test has an expected race. Sleeping for 25 ms prevents - // it on most fast machines, causing the next fetch() call to - // succeed quickly. But if we do get errors, fetch() will retry 5 - // times with some delays between. - time.Sleep(25 * time.Millisecond) + // Close all the idle connections in a way that's similar to + // the server hanging up on us. We don't use + // httptest.Server.CloseClientConnections because it's + // best-effort and stops blocking after 5 seconds. On a loaded + // machine running many tests concurrently it's possible for + // that method to be async and cause the body3 fetch below to + // run on an old connection. This function is synchronous. + ExportCloseTransportConnsAbruptly(c.Transport.(*Transport)) body3 := fetch(3, 5) |