aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Gerrand <adg@golang.org>2011-03-30 11:40:00 +1100
committerAndrew Gerrand <adg@golang.org>2011-03-30 11:40:00 +1100
commitd54c4ecc329c22a8a79dd4d91a4df8bf41920bf4 (patch)
tree87de5a7f03387836e644ccbd2162e3c373ad7900
parent57c6d36f954bdc0fa60f4312d2e7b93e0fab7a46 (diff)
downloadgo-d54c4ecc329c22a8a79dd4d91a4df8bf41920bf4.tar.gz
go-d54c4ecc329c22a8a79dd4d91a4df8bf41920bf4.zip
time: make TestAfterQueuing retry 3 times before declaring failure.
I'm in two minds as to whether this should be a function of gotest. Tests that can flake out like this should be rare enough that we needn't add more mechanism. R=r CC=golang-dev https://golang.org/cl/4335042
-rw-r--r--src/pkg/time/sleep_test.go23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/pkg/time/sleep_test.go b/src/pkg/time/sleep_test.go
index 8bf599c3e1..25e79f9fbc 100644
--- a/src/pkg/time/sleep_test.go
+++ b/src/pkg/time/sleep_test.go
@@ -5,6 +5,7 @@
package time_test
import (
+ "fmt"
"os"
"syscall"
"testing"
@@ -132,6 +133,21 @@ func TestAfterStop(t *testing.T) {
}
}
+func TestAfterQueuing(t *testing.T) {
+ // This test flakes out on some systems,
+ // so we'll try it a few times before declaring it a failure.
+ const attempts = 3
+ err := os.NewError("!=nil")
+ for i := 0; i < attempts && err != nil; i++ {
+ if err = testAfterQueuing(t); err != nil {
+ t.Logf("attempt %v failed: %v", i, err)
+ }
+ }
+ if err != nil {
+ t.Fatal(err)
+ }
+}
+
var slots = []int{5, 3, 6, 6, 6, 1, 1, 2, 7, 9, 4, 8, 0}
type afterResult struct {
@@ -143,7 +159,7 @@ func await(slot int, result chan<- afterResult, ac <-chan int64) {
result <- afterResult{slot, <-ac}
}
-func TestAfterQueuing(t *testing.T) {
+func testAfterQueuing(t *testing.T) os.Error {
const (
Delta = 100 * 1e6
)
@@ -160,13 +176,14 @@ func TestAfterQueuing(t *testing.T) {
for _, slot := range slots {
r := <-result
if r.slot != slot {
- t.Fatalf("after queue got slot %d, expected %d", r.slot, slot)
+ return fmt.Errorf("after queue got slot %d, expected %d", r.slot, slot)
}
ns := r.t - t0
target := int64(slot * Delta)
slop := int64(Delta) / 4
if ns < target-slop || ns > target+slop {
- t.Fatalf("after queue slot %d arrived at %g, expected [%g,%g]", slot, float64(ns), float64(target-slop), float64(target+slop))
+ return fmt.Errorf("after queue slot %d arrived at %g, expected [%g,%g]", slot, float64(ns), float64(target-slop), float64(target+slop))
}
}
+ return nil
}