aboutsummaryrefslogtreecommitdiff
path: root/src/net/timeout_test.go
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2023-08-31 15:22:14 -0400
committerGopher Robot <gobot@golang.org>2023-09-01 15:17:54 +0000
commite3ef8d18102d923a1dbd499ce5ae21ee70e13638 (patch)
tree7eb3c514f6c53bd573c152533312165d50d203b2 /src/net/timeout_test.go
parentb4c889b5618f328866579671a532c8e617cdb507 (diff)
downloadgo-e3ef8d18102d923a1dbd499ce5ae21ee70e13638.tar.xz
net: deflake TestDialTimeout on windows
The time granularity on windows is large enough that setting even an implausibly small timeout still gives ConnectEx enough time to succeed before the timeout expires. That causes TestDialTimeout to sometimes flake, because it expects to be able to provoke a timeout using some nonzero duration. This change takes a two-pronged approach to address the problem: 1. We can set a deadline on the FD more aggressively. (If the Context has already expired, or the deadline is already known, we can go ahead and set it on the fd without waiting for a background goroutine to get around to it.) 2. We can reintroduce a test hook to ensure that Dial takes a measurable amount of time before it completes, so that setting an implausibly short deadline sets that deadline in the past instead of the future. Together, these reduce the flake rate on a windows-amd64-longtest gomote from around 1-in-10 to less than 1-in-2000. For #62377. Change-Id: I03975c32f61fffa9f6f84efb3c474a01ac5a0d1e Reviewed-on: https://go-review.googlesource.com/c/go/+/524936 Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/net/timeout_test.go')
-rw-r--r--src/net/timeout_test.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/net/timeout_test.go b/src/net/timeout_test.go
index 581e1148c0..2e23b2f5df 100644
--- a/src/net/timeout_test.go
+++ b/src/net/timeout_test.go
@@ -18,6 +18,21 @@ import (
"time"
)
+func init() {
+ // Install a hook to ensure that a 1ns timeout will always
+ // be exceeded by the time Dial gets to the relevant system call.
+ //
+ // Without this, systems with a very large timer granularity — such as
+ // Windows — may be able to accept connections without measurably exceeding
+ // even an implausibly short deadline.
+ testHookStepTime = func() {
+ now := time.Now()
+ for time.Since(now) == 0 {
+ time.Sleep(1 * time.Nanosecond)
+ }
+ }
+}
+
var dialTimeoutTests = []struct {
initialTimeout time.Duration
initialDelta time.Duration // for deadline