]> Cypherpunks repositories - gostls13.git/commitdiff
time: use longer delta duration for TestAfterQueueing retries
authorMatthew Dempsky <mdempsky@google.com>
Wed, 29 Apr 2015 20:36:34 +0000 (13:36 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Wed, 29 Apr 2015 21:43:29 +0000 (21:43 +0000)
The TestAfterQueueing test is inherently flaky because it relies on
independent kernel threads being scheduled within the "delta" duration
of each other.  Normally, delta is 100ms but during "short" testing,
it's reduced to 20ms.

On at least OpenBSD, the CPU scheduler operates in 10ms time slices,
so high system load (e.g., from running multiple Go unit tests in
parallel, as happens during all.bash) can occasionally cause >20ms
scheduling delays and result in test flaking.  This manifests as issue
9903, which is the currently the most common OpenBSD flake.

To mitigate this delay, only reduce the delta duration to 20ms for the
first attempt during short testing.  If this fails and the test is
reattempted, subsequent attempts instead use a full 100ms delta.

Fixes #9903.

Change-Id: I11bdfa939e5be915f67ffad8a8aef6ed8772159a
Reviewed-on: https://go-review.googlesource.com/9510
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/time/sleep_test.go

index 6452a9e0274753c83a5010d1803a001ed1344805..d0962ecf85b3a17e43dad0a1f54880126e69919a 100644 (file)
@@ -227,7 +227,11 @@ func TestAfterQueuing(t *testing.T) {
        const attempts = 3
        err := errors.New("!=nil")
        for i := 0; i < attempts && err != nil; i++ {
-               if err = testAfterQueuing(t); err != nil {
+               delta := 100 * Millisecond
+               if i == 0 && testing.Short() {
+                       delta = 20 * Millisecond
+               }
+               if err = testAfterQueuing(t, delta); err != nil {
                        t.Logf("attempt %v failed: %v", i, err)
                }
        }
@@ -247,11 +251,7 @@ func await(slot int, result chan<- afterResult, ac <-chan Time) {
        result <- afterResult{slot, <-ac}
 }
 
-func testAfterQueuing(t *testing.T) error {
-       Delta := 100 * Millisecond
-       if testing.Short() {
-               Delta = 20 * Millisecond
-       }
+func testAfterQueuing(t *testing.T, delta Duration) error {
        // make the result channel buffered because we don't want
        // to depend on channel queueing semantics that might
        // possibly change in the future.
@@ -259,7 +259,7 @@ func testAfterQueuing(t *testing.T) error {
 
        t0 := Now()
        for _, slot := range slots {
-               go await(slot, result, After(Duration(slot)*Delta))
+               go await(slot, result, After(Duration(slot)*delta))
        }
        sort.Ints(slots)
        for _, slot := range slots {
@@ -268,9 +268,9 @@ func testAfterQueuing(t *testing.T) error {
                        return fmt.Errorf("after slot %d, expected %d", r.slot, slot)
                }
                dt := r.t.Sub(t0)
-               target := Duration(slot) * Delta
-               if dt < target-Delta/2 || dt > target+Delta*10 {
-                       return fmt.Errorf("After(%s) arrived at %s, expected [%s,%s]", target, dt, target-Delta/2, target+Delta*10)
+               target := Duration(slot) * delta
+               if dt < target-delta/2 || dt > target+delta*10 {
+                       return fmt.Errorf("After(%s) arrived at %s, expected [%s,%s]", target, dt, target-delta/2, target+delta*10)
                }
        }
        return nil