diff options
| author | Bryan C. Mills <bcmills@google.com> | 2023-09-11 16:17:03 -0400 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-09-13 20:57:25 +0000 |
| commit | 6760f20ef58a8d99ffe898b51d938577ab19c900 (patch) | |
| tree | 849512ebca5f60d98a94a257471a3971fe356c48 /src/net/http/export_test.go | |
| parent | 545e4f38e0c177484ffa409c2fa1265423a5855f (diff) | |
| download | go-6760f20ef58a8d99ffe898b51d938577ab19c900.tar.xz | |
net/http: scale rstAvoidanceDelay to reduce test flakiness
As far as I can tell, some flakiness is unavoidable in tests
that race a large client request write against a server's response
when the server doesn't read the full request.
It does not appear to be possible to simultaneously ensure that
well-behaved clients see EOF instead of ECONNRESET and also prevent
misbehaving clients from consuming arbitrary server resources.
(See RFC 7230 ยง6.6 for more detail.)
Since there doesn't appear to be a way to cleanly eliminate
this source of flakiness, we can instead work around it:
we can allow the test to adjust the hard-coded delay if it
sees a plausibly-related failure, so that the test can retry
with a longer delay.
As a nice side benefit, this also allows the tests to run more quickly
in the typical case: since the test will retry in case of spurious
failures, we can start with an aggressively short delay, and only back
off to a longer one if it is really needed on the specific machine
running the test.
Fixes #57084.
Fixes #51104.
For #58398.
Change-Id: Ia4050679f0777e5eeba7670307a77d93cfce856f
Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest-race,gotip-linux-amd64-race,gotip-windows-amd64-race
Reviewed-on: https://go-review.googlesource.com/c/go/+/527196
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Diffstat (limited to 'src/net/http/export_test.go')
| -rw-r--r-- | src/net/http/export_test.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/net/http/export_test.go b/src/net/http/export_test.go index 5d198f3f89..7e6d3d8e30 100644 --- a/src/net/http/export_test.go +++ b/src/net/http/export_test.go @@ -315,3 +315,21 @@ func ResponseWriterConnForTesting(w ResponseWriter) (c net.Conn, ok bool) { } return nil, false } + +func init() { + // Set the default rstAvoidanceDelay to the minimum possible value to shake + // out tests that unexpectedly depend on it. Such tests should use + // runTimeSensitiveTest and SetRSTAvoidanceDelay to explicitly raise the delay + // if needed. + rstAvoidanceDelay = 1 * time.Nanosecond +} + +// SetRSTAvoidanceDelay sets how long we are willing to wait between calling +// CloseWrite on a connection and fully closing the connection. +func SetRSTAvoidanceDelay(t *testing.T, d time.Duration) { + prevDelay := rstAvoidanceDelay + t.Cleanup(func() { + rstAvoidanceDelay = prevDelay + }) + rstAvoidanceDelay = d +} |
