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 <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Bryan C. Mills 2020-04-08 16:28:33 -04:00
parent 7694bf329d
commit ddfc55b076

View File

@ -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