@@ -348,7 +348,13 @@ func (f *fakeTimer) Stop() bool {
348
348
// Reset conditionally updates the firing time of the timer. If the
349
349
// timer has neither fired nor been stopped then this call resets the
350
350
// timer to the fake clock's "now" + d and returns true, otherwise
351
- // this call returns false. This is like time.Timer::Reset.
351
+ // it creates a new waiter, adds it to the clock, and returns true.
352
+ //
353
+ // It is not possible to return false, because a fake timer can be reset
354
+ // from any state (waiting to fire, already fired, and stopped).
355
+ //
356
+ // See the GoDoc for time.Timer::Reset for more context on why
357
+ // the return value of Reset() is not useful.
352
358
func (f * fakeTimer ) Reset (d time.Duration ) bool {
353
359
f .fakeClock .lock .Lock ()
354
360
defer f .fakeClock .lock .Unlock ()
@@ -360,7 +366,15 @@ func (f *fakeTimer) Reset(d time.Duration) bool {
360
366
return true
361
367
}
362
368
}
363
- return false
369
+ // No existing waiter, timer has already fired or been reset.
370
+ // We should still enable Reset() to succeed by creating a
371
+ // new waiter and adding it to the clock's waiters.
372
+ newWaiter := fakeClockWaiter {
373
+ targetTime : f .fakeClock .time .Add (d ),
374
+ destChan : seekChan ,
375
+ }
376
+ f .fakeClock .waiters = append (f .fakeClock .waiters , newWaiter )
377
+ return true
364
378
}
365
379
366
380
// Ticker defines the Ticker interface
0 commit comments