]> Cypherpunks repositories - gostls13.git/commitdiff
time: fallback to slower TestTicker test after one failure
authorDamien Neil <dneil@google.com>
Wed, 4 Aug 2021 23:07:28 +0000 (16:07 -0700)
committerDamien Neil <dneil@google.com>
Wed, 6 Oct 2021 23:01:01 +0000 (23:01 +0000)
TestTicker is sensitive to overloaded or slow systems, where a 20ms
ticker running for 10 ticks has a total run time out of the range
[110ms, 290ms]. To counter this flakiness, it tries five times to
get a successful result. This is insufficient--an overloaded test
machine can introduce more than 100ms of delay across the test.

Reduce the five attempts to two, but use a 1s ticker for 8 ticks
in the second attempt.

Updates #46474.
Updates #35692.

Change-Id: Ibd5187b00ccceeb981b652f2af9a1c3766357b78
Reviewed-on: https://go-review.googlesource.com/c/go/+/339892
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/time/tick_test.go

index b5d0a189bc84045782f5d190af1b5b5b15a0afca..d8cd59228f0fd47adf01273d384fd48a876f44c4 100644 (file)
@@ -15,10 +15,11 @@ func TestTicker(t *testing.T) {
        // We want to test that a ticker takes as much time as expected.
        // Since we don't want the test to run for too long, we don't
        // want to use lengthy times. This makes the test inherently flaky.
-       // So only report an error if it fails five times in a row.
+       // Start with a short time, but try again with a long one if the
+       // first test fails.
 
-       count := 10
-       delta := 20 * Millisecond
+       baseCount := 10
+       baseDelta := 20 * Millisecond
 
        // On Darwin ARM64 the tick frequency seems limited. Issue 35692.
        if (runtime.GOOS == "darwin" || runtime.GOOS == "ios") && runtime.GOARCH == "arm64" {
@@ -27,8 +28,8 @@ func TestTicker(t *testing.T) {
                // Since tick frequency is limited on Darwin ARM64, use even
                // number to give the ticks more time to let the test pass.
                // See CL 220638.
-               count = 6
-               delta = 100 * Millisecond
+               baseCount = 6
+               baseDelta = 100 * Millisecond
        }
 
        var errs []string
@@ -38,7 +39,17 @@ func TestTicker(t *testing.T) {
                }
        }
 
-       for i := 0; i < 5; i++ {
+       for _, test := range []struct {
+               count int
+               delta Duration
+       }{{
+               count: baseCount,
+               delta: baseDelta,
+       }, {
+               count: 8,
+               delta: 1 * Second,
+       }} {
+               count, delta := test.count, test.delta
                ticker := NewTicker(delta)
                t0 := Now()
                for i := 0; i < count/2; i++ {