aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/time/sleep_test.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2020-01-02 15:05:27 -0800
committerIan Lance Taylor <iant@golang.org>2020-01-21 23:53:22 -0800
commit5a8ea165926cb0737ab03bc48c18dc5198ab5305 (patch)
tree962dc3357c57f019f85658f99e2e753e30201c27 /libgo/go/time/sleep_test.go
parent6ac6529e155c9baa0aaaed7aca06bd38ebda5b43 (diff)
downloadgcc-5a8ea165926cb0737ab03bc48c18dc5198ab5305.zip
gcc-5a8ea165926cb0737ab03bc48c18dc5198ab5305.tar.gz
gcc-5a8ea165926cb0737ab03bc48c18dc5198ab5305.tar.bz2
libgo: update to Go1.14beta1
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/214297
Diffstat (limited to 'libgo/go/time/sleep_test.go')
-rw-r--r--libgo/go/time/sleep_test.go71
1 files changed, 51 insertions, 20 deletions
diff --git a/libgo/go/time/sleep_test.go b/libgo/go/time/sleep_test.go
index 42df6d1..26cc488 100644
--- a/libgo/go/time/sleep_test.go
+++ b/libgo/go/time/sleep_test.go
@@ -235,28 +235,59 @@ func TestAfterTick(t *testing.T) {
}
func TestAfterStop(t *testing.T) {
- AfterFunc(100*Millisecond, func() {})
- t0 := NewTimer(50 * Millisecond)
- c1 := make(chan bool, 1)
- t1 := AfterFunc(150*Millisecond, func() { c1 <- true })
- c2 := After(200 * Millisecond)
- if !t0.Stop() {
- t.Fatalf("failed to stop event 0")
- }
- if !t1.Stop() {
- t.Fatalf("failed to stop event 1")
- }
- <-c2
- select {
- case <-t0.C:
- t.Fatalf("event 0 was not stopped")
- case <-c1:
- t.Fatalf("event 1 was not stopped")
- default:
+ // We want to test that we stop a timer before it runs.
+ // We also want to test that it didn't run after a longer timer.
+ // Since we don't want the test to run for too long, we don't
+ // want to use lengthy times. That makes the test inherently flaky.
+ // So only report an error if it fails five times in a row.
+
+ var errs []string
+ logErrs := func() {
+ for _, e := range errs {
+ t.Log(e)
+ }
}
- if t1.Stop() {
- t.Fatalf("Stop returned true twice")
+
+ for i := 0; i < 5; i++ {
+ AfterFunc(100*Millisecond, func() {})
+ t0 := NewTimer(50 * Millisecond)
+ c1 := make(chan bool, 1)
+ t1 := AfterFunc(150*Millisecond, func() { c1 <- true })
+ c2 := After(200 * Millisecond)
+ if !t0.Stop() {
+ errs = append(errs, "failed to stop event 0")
+ continue
+ }
+ if !t1.Stop() {
+ 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) {