]> Cypherpunks repositories - gostls13.git/commitdiff
time: increase slop for TestTicker
authorIan Lance Taylor <iant@golang.org>
Tue, 27 Apr 2021 00:49:28 +0000 (17:49 -0700)
committerIan Lance Taylor <iant@golang.org>
Tue, 27 Apr 2021 19:37:31 +0000 (19:37 +0000)
Also sleep a bit each time it fails, in case the system is overloaded.

Fixes #37332

Change-Id: Iabf3d0a27b5834c1e2a87c826b6206146b4f62c5
Reviewed-on: https://go-review.googlesource.com/c/go/+/313849
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
src/time/tick_test.go

index 9a1cdf9ab2eaa57b619a6e697767c2cb98c32a51..b5d0a189bc84045782f5d190af1b5b5b15a0afca 100644 (file)
@@ -52,9 +52,14 @@ func TestTicker(t *testing.T) {
                t1 := Now()
                dt := t1.Sub(t0)
                target := 3 * delta * Duration(count/2)
-               slop := target * 2 / 10
+               slop := target * 3 / 10
                if dt < target-slop || dt > target+slop {
-                       errs = append(errs, fmt.Sprintf("%d %s ticks took %s, expected [%s,%s]", count, delta, dt, target-slop, target+slop))
+                       errs = append(errs, fmt.Sprintf("%d %s ticks then %d %s ticks took %s, expected [%s,%s]", count/2, delta, count/2, delta*2, dt, target-slop, target+slop))
+                       if dt > target+slop {
+                               // System may be overloaded; sleep a bit
+                               // in the hopes it will recover.
+                               Sleep(Second / 2)
+                       }
                        continue
                }
                // Now test that the ticker stopped.