runtime: improve reliability of timers test in CI

Этот коммит содержится в:
Kenneth Bell 2022-07-02 17:19:36 +01:00 коммит произвёл Ron Evans
родитель 24b45555bd
коммит 12d63d9642
2 изменённых файлов: 27 добавлений и 27 удалений

36
testdata/timers.go предоставленный
Просмотреть файл

@ -4,38 +4,38 @@ import "time"
func main() {
// Test ticker.
ticker := time.NewTicker(time.Millisecond * 160)
ticker := time.NewTicker(time.Millisecond * 250)
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")
time.Sleep(time.Millisecond * 125)
println(" - after 125ms")
time.Sleep(time.Millisecond * 250)
println(" - after 375ms")
time.Sleep(time.Millisecond * 250)
println(" - after 625ms")
}()
<-ticker.C
println("waited on ticker at 160ms")
println("waited on ticker at 250ms")
<-ticker.C
println("waited on ticker at 320ms")
println("waited on ticker at 500ms")
ticker.Stop()
time.Sleep(time.Millisecond * 400)
time.Sleep(time.Millisecond * 500)
select {
case <-ticker.C:
println("fail: ticker should have stopped!")
default:
println("ticker was stopped (didn't send anything after 400ms)")
println("ticker was stopped (didn't send anything after 500ms)")
}
timer := time.NewTimer(time.Millisecond * 160)
timer := time.NewTimer(time.Millisecond * 250)
println("waiting on timer")
go func() {
time.Sleep(time.Millisecond * 80)
println(" - after 80ms")
time.Sleep(time.Millisecond * 160)
println(" - after 240ms")
time.Sleep(time.Millisecond * 125)
println(" - after 125ms")
time.Sleep(time.Millisecond * 250)
println(" - after 250ms")
}()
<-timer.C
println("waited on timer at 160ms")
time.Sleep(time.Millisecond * 160)
println("waited on timer at 250ms")
time.Sleep(time.Millisecond * 250)
}

18
testdata/timers.txt предоставленный
Просмотреть файл

@ -1,11 +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)
- after 125ms
waited on ticker at 250ms
- after 375ms
waited on ticker at 500ms
- after 625ms
ticker was stopped (didn't send anything after 500ms)
waiting on timer
- after 80ms
waited on timer at 160ms
- after 240ms
- after 125ms
waited on timer at 250ms
- after 250ms