From ddfc55b076d945f215875d6b65c36fc53b332cc1 Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Wed, 8 Apr 2020 16:28:33 -0400 Subject: [PATCH] os/signal: increase settle time in tests I noticed a timeout in TestIgnore in https://build.golang.org/log/52d83a72f3a5ea9a16eb5d670c729694144f9624, which suggests that the settle time is currently set too low. I've also added a check for the same GO_TEST_TIMEOUT_SCALE used in TestTerminalSignal, so that if this builder remains too slow we can increase the builder's scale factor rather than the test's baseline running time. Updates #33174 Change-Id: I18b10eaa3bb5ae2f604300aedaaf6f79ee7ad567 Reviewed-on: https://go-review.googlesource.com/c/go/+/227649 Run-TryBot: Bryan C. Mills TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/os/signal/signal_test.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/os/signal/signal_test.go b/src/os/signal/signal_test.go index e5dcda4a2b..50e21d4e64 100644 --- a/src/os/signal/signal_test.go +++ b/src/os/signal/signal_test.go @@ -25,16 +25,30 @@ import ( // settleTime is an upper bound on how long we expect signals to take to be // delivered. Lower values make the test faster, but also flakier — especially // on heavily loaded systems. -const settleTime = 100 * time.Millisecond +// +// The current value is set based on flakes observed in the Go builders. +var settleTime = 250 * time.Millisecond + +func init() { + if s := os.Getenv("GO_TEST_TIMEOUT_SCALE"); s != "" { + if scale, err := strconv.Atoi(s); err == nil { + settleTime *= time.Duration(scale) + } + } +} func waitSig(t *testing.T, c <-chan os.Signal, sig os.Signal) { + t.Helper() waitSig1(t, c, sig, false) } func waitSigAll(t *testing.T, c <-chan os.Signal, sig os.Signal) { + t.Helper() waitSig1(t, c, sig, true) } func waitSig1(t *testing.T, c <-chan os.Signal, sig os.Signal, all bool) { + t.Helper() + // Sleep multiple times to give the kernel more tries to // deliver the signal. start := time.Now() @@ -58,7 +72,7 @@ func waitSig1(t *testing.T, c <-chan os.Signal, sig os.Signal, all bool) { timer.Reset(settleTime / 10) } } - t.Fatalf("timeout waiting for %v", sig) + t.Fatalf("timeout after %v waiting for %v", settleTime, sig) } // quiesce waits until we can be reasonably confident that all pending signals