Commit e82277b8 authored by Prashanth B's avatar Prashanth B

Merge pull request #17302 from bprashanth/wait_leak

Fix timer leak in wait.Poll
parents 01656fd9 eab22ff9
......@@ -132,7 +132,12 @@ func poller(interval, timeout time.Duration) WaitFunc {
for {
select {
case <-tick.C:
ch <- struct{}{}
// If the consumer isn't ready for this signal drop it and
// check the other channels.
select {
case ch <- struct{}{}:
default:
}
case <-after:
return
case <-done:
......
......@@ -257,3 +257,18 @@ func TestWaitFor(t *testing.T) {
}
}
}
func TestWaitForWithDelay(t *testing.T) {
done := make(chan struct{})
defer close(done)
WaitFor(poller(time.Millisecond, util.ForeverTestTimeout), func() (bool, error) {
time.Sleep(10 * time.Millisecond)
return true, nil
}, done)
// If polling goroutine doesn't see the done signal it will leak timers.
select {
case done <- struct{}{}:
case <-time.After(util.ForeverTestTimeout):
t.Errorf("expected an ack of the done signal.")
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment