diff options
Diffstat (limited to 'testdata')
-rw-r--r-- | testdata/timers.go | 41 | ||||
-rw-r--r-- | testdata/timers.txt | 11 |
2 files changed, 52 insertions, 0 deletions
diff --git a/testdata/timers.go b/testdata/timers.go new file mode 100644 index 000000000..99591c822 --- /dev/null +++ b/testdata/timers.go @@ -0,0 +1,41 @@ +package main + +import "time" + +func main() { + // Test ticker. + ticker := time.NewTicker(time.Millisecond * 160) + println("waiting on ticker") + go func() { + time.Sleep(time.Millisecond * 80) + println(" - after 80ms") + time.Sleep(time.Millisecond * 160) + println(" - after 240ms") + time.Sleep(time.Millisecond * 160) + println(" - after 400ms") + }() + <-ticker.C + println("waited on ticker at 160ms") + <-ticker.C + println("waited on ticker at 320ms") + ticker.Stop() + time.Sleep(time.Millisecond * 400) + select { + case <-ticker.C: + println("fail: ticker should have stopped!") + default: + println("ticker was stopped (didn't send anything after 400ms)") + } + + timer := time.NewTimer(time.Millisecond * 160) + println("waiting on timer") + go func() { + time.Sleep(time.Millisecond * 80) + println(" - after 80ms") + time.Sleep(time.Millisecond * 160) + println(" - after 240ms") + }() + <-timer.C + println("waited on timer at 160ms") + time.Sleep(time.Millisecond * 160) +} diff --git a/testdata/timers.txt b/testdata/timers.txt new file mode 100644 index 000000000..24142d541 --- /dev/null +++ b/testdata/timers.txt @@ -0,0 +1,11 @@ +waiting on ticker + - after 80ms +waited on ticker at 160ms + - after 240ms +waited on ticker at 320ms + - after 400ms +ticker was stopped (didn't send anything after 400ms) +waiting on timer + - after 80ms +waited on timer at 160ms + - after 240ms |