mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-07-26 06:38:42 +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
|
||||
println("waited on ticker at 1000ms")
|
||||
ticker.Stop()
|
||||
// Drain any tick that was already queued before Stop took effect.
|
||||
select {
|
||||
case <-ticker.C:
|
||||
default:
|
||||
}
|
||||
time.Sleep(time.Millisecond * 750)
|
||||
select {
|
||||
case <-ticker.C:
|
||||
|
||||
Reference in New Issue
Block a user