aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2017-07-07 13:09:20 -1000
committerJosh Bleecher Snyder <josharian@gmail.com>2017-07-08 02:10:12 +0000
commita1e7fb4eed7fbb002d2fabbd6a809a1a49dca711 (patch)
tree2d9099210b76b4081f9b0942c6b7f07f29950413
parent093adeef4004fd029de1a8fd138802607265dc73 (diff)
downloadgo-a1e7fb4eed7fbb002d2fabbd6a809a1a49dca711.tar.gz
go-a1e7fb4eed7fbb002d2fabbd6a809a1a49dca711.zip
test: deflake chan/select3.go
On a slow or distracted machine, 0.1s is sometimes not long enough for a non-blocking function call to complete. This causes rare test flakes. They can be easily reproduced by reducing the wait time to (say) 100ns. For non-blocking functions, increase the window from 100ms to 10s. Using different windows for block and non-blocking functions, allows us to reduce the time for blocking functions. The risk here is false negatives, but that risk is low; this test is run repeatedly on many fast machines, for which 10ms is ample time. This reduces the time required to run the test by a factor of 10, from ~1s to ~100ms. Fixes #20299 Change-Id: Ice9a641a66c6c101d738a2ebe1bcb144ae3c9916 Reviewed-on: https://go-review.googlesource.com/47812 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
-rw-r--r--test/chan/select3.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/test/chan/select3.go b/test/chan/select3.go
index e9391f55c7..dd14c7381e 100644
--- a/test/chan/select3.go
+++ b/test/chan/select3.go
@@ -40,8 +40,15 @@ func testBlock(signal string, f func()) {
c <- never // f didn't block
}()
go func() {
- time.Sleep(1e8) // 0.1s seems plenty long
- c <- always // f blocked always
+ if signal == never {
+ // Wait a long time to make sure that we don't miss our window by accident on a slow machine.
+ time.Sleep(10 * time.Second)
+ } else {
+ // Wait as short a time as we can without false negatives.
+ // 10ms should be long enough to catch most failures.
+ time.Sleep(10 * time.Millisecond)
+ }
+ c <- always // f blocked always
}()
if <-c != signal {
panic(signal + " block")