mirror of https://github.com/golang/go.git
time: only fail TestAfterStop if it fails five times in a row
The test is inherently slightly flaky, so repeat to reduce flakiness. Fixes #35537 Change-Id: Id918d48d33c7d5e19c4f24df104adc7fbf3720f2 Reviewed-on: https://go-review.googlesource.com/c/go/+/207457 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
acb9ac0751
commit
dab1a10a98
|
|
@ -235,28 +235,59 @@ func TestAfterTick(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAfterStop(t *testing.T) {
|
func TestAfterStop(t *testing.T) {
|
||||||
AfterFunc(100*Millisecond, func() {})
|
// We want to test that we stop a timer before it runs.
|
||||||
t0 := NewTimer(50 * Millisecond)
|
// We also want to test that it didn't run after a longer timer.
|
||||||
c1 := make(chan bool, 1)
|
// Since we don't want the test to run for too long, we don't
|
||||||
t1 := AfterFunc(150*Millisecond, func() { c1 <- true })
|
// want to use lengthy times. That makes the test inherently flaky.
|
||||||
c2 := After(200 * Millisecond)
|
// So only report an error if it fails five times in a row.
|
||||||
if !t0.Stop() {
|
|
||||||
t.Fatalf("failed to stop event 0")
|
var errs []string
|
||||||
|
logErrs := func() {
|
||||||
|
for _, e := range errs {
|
||||||
|
t.Log(e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if !t1.Stop() {
|
|
||||||
t.Fatalf("failed to stop event 1")
|
for i := 0; i < 5; i++ {
|
||||||
}
|
AfterFunc(100*Millisecond, func() {})
|
||||||
<-c2
|
t0 := NewTimer(50 * Millisecond)
|
||||||
select {
|
c1 := make(chan bool, 1)
|
||||||
case <-t0.C:
|
t1 := AfterFunc(150*Millisecond, func() { c1 <- true })
|
||||||
t.Fatalf("event 0 was not stopped")
|
c2 := After(200 * Millisecond)
|
||||||
case <-c1:
|
if !t0.Stop() {
|
||||||
t.Fatalf("event 1 was not stopped")
|
errs = append(errs, "failed to stop event 0")
|
||||||
default:
|
continue
|
||||||
}
|
}
|
||||||
if t1.Stop() {
|
if !t1.Stop() {
|
||||||
t.Fatalf("Stop returned true twice")
|
errs = append(errs, "failed to stop event 1")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
<-c2
|
||||||
|
select {
|
||||||
|
case <-t0.C:
|
||||||
|
errs = append(errs, "event 0 was not stopped")
|
||||||
|
continue
|
||||||
|
case <-c1:
|
||||||
|
errs = append(errs, "event 1 was not stopped")
|
||||||
|
continue
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
if t1.Stop() {
|
||||||
|
errs = append(errs, "Stop returned true twice")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test passed, so all done.
|
||||||
|
if len(errs) > 0 {
|
||||||
|
t.Logf("saw %d errors, ignoring to avoid flakiness", len(errs))
|
||||||
|
logErrs()
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t.Errorf("saw %d errors", len(errs))
|
||||||
|
logErrs()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAfterQueuing(t *testing.T) {
|
func TestAfterQueuing(t *testing.T) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue