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

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

@ -1,11 +1,11 @@
waiting on ticker waiting on ticker
- after 80ms - after 125ms
waited on ticker at 160ms waited on ticker at 250ms
- after 240ms - after 375ms
waited on ticker at 320ms waited on ticker at 500ms
- after 400ms - after 625ms
ticker was stopped (didn't send anything after 400ms) ticker was stopped (didn't send anything after 500ms)
waiting on timer waiting on timer
- after 80ms - after 125ms
waited on timer at 160ms waited on timer at 250ms
- after 240ms - after 250ms