Skip to content

Commit 944176b

Browse files
committed
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>
1 parent c396418 commit 944176b

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

testdata/timers.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ func main() {
2121
<-ticker.C
2222
println("waited on ticker at 1000ms")
2323
ticker.Stop()
24+
// Drain any tick that was already queued before Stop took effect.
25+
select {
26+
case <-ticker.C:
27+
default:
28+
}
2429
time.Sleep(time.Millisecond * 750)
2530
select {
2631
case <-ticker.C:

0 commit comments

Comments
 (0)