From d12b532265603bdb2ce2fcb4bc3a53c03771d370 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Wed, 29 Apr 2015 13:36:34 -0700 Subject: [PATCH] time: use longer delta duration for TestAfterQueueing retries 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 TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/time/sleep_test.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/time/sleep_test.go b/src/time/sleep_test.go index 6452a9e027..d0962ecf85 100644 --- a/src/time/sleep_test.go +++ b/src/time/sleep_test.go @@ -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 -- 2.48.1