Browse Source

testdata: increase timings used for timers test to try to avoid race condition errors on macOS CI

Signed-off-by: deadprogram <ron@hybridgroup.com>
pull/3204/head
deadprogram 2 years ago
committed by Ron Evans
parent
commit
c2fb1e776a
  1. 50
      testdata/timers.go
  2. 22
      testdata/timers.txt

50
testdata/timers.go

@ -4,51 +4,51 @@ import "time"
func main() { func main() {
// Test ticker. // Test ticker.
ticker := time.NewTicker(time.Millisecond * 250) ticker := time.NewTicker(time.Millisecond * 500)
println("waiting on ticker") println("waiting on ticker")
go func() { go func() {
time.Sleep(time.Millisecond * 125) time.Sleep(time.Millisecond * 150)
println(" - after 125ms") println(" - after 150ms")
time.Sleep(time.Millisecond * 250) time.Sleep(time.Millisecond * 200)
println(" - after 375ms") println(" - after 200ms")
time.Sleep(time.Millisecond * 250) time.Sleep(time.Millisecond * 300)
println(" - after 625ms") println(" - after 300ms")
}() }()
<-ticker.C <-ticker.C
println("waited on ticker at 250ms")
<-ticker.C
println("waited on ticker at 500ms") println("waited on ticker at 500ms")
<-ticker.C
println("waited on ticker at 1000ms")
ticker.Stop() ticker.Stop()
time.Sleep(time.Millisecond * 500) time.Sleep(time.Millisecond * 750)
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 500ms)") println("ticker was stopped (didn't send anything after 750ms)")
} }
timer := time.NewTimer(time.Millisecond * 250) timer := time.NewTimer(time.Millisecond * 500)
println("waiting on timer") println("waiting on timer")
go func() { go func() {
time.Sleep(time.Millisecond * 125) time.Sleep(time.Millisecond * 200)
println(" - after 125ms") println(" - after 200ms")
time.Sleep(time.Millisecond * 250) time.Sleep(time.Millisecond * 400)
println(" - after 250ms") println(" - after 400ms")
}() }()
<-timer.C <-timer.C
println("waited on timer at 250ms") println("waited on timer at 500ms")
time.Sleep(time.Millisecond * 250) time.Sleep(time.Millisecond * 500)
reset := timer.Reset(time.Millisecond * 250) reset := timer.Reset(time.Millisecond * 500)
println("timer reset:", reset) println("timer reset:", reset)
println("waiting on timer") println("waiting on timer")
go func() { go func() {
time.Sleep(time.Millisecond * 125) time.Sleep(time.Millisecond * 200)
println(" - after 125ms") println(" - after 200ms")
time.Sleep(time.Millisecond * 250) time.Sleep(time.Millisecond * 400)
println(" - after 250ms") println(" - after 400ms")
}() }()
<-timer.C <-timer.C
println("waited on timer at 250ms") println("waited on timer at 500ms")
time.Sleep(time.Millisecond * 250) time.Sleep(time.Millisecond * 500)
} }

22
testdata/timers.txt

@ -1,16 +1,16 @@
waiting on ticker waiting on ticker
- after 125ms - after 150ms
waited on ticker at 250ms - after 200ms
- after 375ms
waited on ticker at 500ms waited on ticker at 500ms
- after 625ms - after 300ms
ticker was stopped (didn't send anything after 500ms) waited on ticker at 1000ms
ticker was stopped (didn't send anything after 750ms)
waiting on timer waiting on timer
- after 125ms - after 200ms
waited on timer at 250ms waited on timer at 500ms
- after 250ms - after 400ms
timer reset: false timer reset: false
waiting on timer waiting on timer
- after 125ms - after 200ms
waited on timer at 250ms waited on timer at 500ms
- after 250ms - after 400ms

Loading…
Cancel
Save