Commit d12b5322 authored by Matthew Dempsky's avatar Matthew Dempsky

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 <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent 3eed422f
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment