]> Cypherpunks repositories - gostls13.git/commitdiff
time: Fix ordering of slots in AfterQueueing test
authorKeith Randall <khr@golang.org>
Mon, 4 May 2015 16:17:53 +0000 (09:17 -0700)
committerKeith Randall <khr@golang.org>
Mon, 4 May 2015 16:49:37 +0000 (16:49 +0000)
We shouldn't sort the slots array, as it is used each time the
test is run.  Tests after the first should continue to use the
unsorted ordering.

Note that this doesn't fix the flaky test.  Just a bug I saw
while investigating.

Change-Id: Ic03cca637829d569d50d3a2278d19410d4dedba9
Reviewed-on: https://go-review.googlesource.com/9637
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/time/sleep_test.go

index d0962ecf85b3a17e43dad0a1f54880126e69919a..2fce75343527701be1c3d2526d4afd9d0d28d00d 100644 (file)
@@ -8,7 +8,6 @@ import (
        "errors"
        "fmt"
        "runtime"
-       "sort"
        "strings"
        "sync"
        "sync/atomic"
@@ -261,14 +260,21 @@ func testAfterQueuing(t *testing.T, delta Duration) error {
        for _, slot := range slots {
                go await(slot, result, After(Duration(slot)*delta))
        }
-       sort.Ints(slots)
-       for _, slot := range slots {
+       var order []int
+       var times []Time
+       for range slots {
                r := <-result
-               if r.slot != slot {
-                       return fmt.Errorf("after slot %d, expected %d", r.slot, slot)
+               order = append(order, r.slot)
+               times = append(times, r.t)
+       }
+       for i := range order {
+               if i > 0 && order[i] < order[i-1] {
+                       return fmt.Errorf("After calls returned out of order: %v", order)
                }
-               dt := r.t.Sub(t0)
-               target := Duration(slot) * delta
+       }
+       for i, t := range times {
+               dt := t.Sub(t0)
+               target := Duration(order[i]) * 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)
                }