mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-19 03:54:01 +00:00
testdata: fix flaky timers test by draining ticker channel after Stop
Ticker.Stop does not drain already-buffered ticks from the channel, so on slow CI runners a tick may already be queued before Stop takes effect, causing a spurious "fail: ticker should have stopped!" failure. Drain the channel immediately after Stop before checking that no new ticks arrive. Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
Vendored
+5
@@ -21,6 +21,11 @@ func main() {
|
|||||||
<-ticker.C
|
<-ticker.C
|
||||||
println("waited on ticker at 1000ms")
|
println("waited on ticker at 1000ms")
|
||||||
ticker.Stop()
|
ticker.Stop()
|
||||||
|
// Drain any tick that was already queued before Stop took effect.
|
||||||
|
select {
|
||||||
|
case <-ticker.C:
|
||||||
|
default:
|
||||||
|
}
|
||||||
time.Sleep(time.Millisecond * 750)
|
time.Sleep(time.Millisecond * 750)
|
||||||
select {
|
select {
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
|
|||||||
Reference in New Issue
Block a user