File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed
Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,14 @@ func NewMockClock() *MockClock {
5050 return & MockClock {now : time .Unix (0 , 0 ), advanceBySem : make (chan struct {}, 1 )}
5151}
5252
53+ // InstantTimer implements a timer that triggers at a fixed instant in time as opposed to after a
54+ // fixed duration from the moment of creation/reset.
55+ //
56+ // In test environments, when using a Timer which fires after a duration, there is a race between
57+ // the goroutine moving time forward using `clock.Advanceby` and the goroutine resetting the
58+ // timer by doing `timer.Reset(desiredInstant.Sub(time.Now()))`. The value of
59+ // `desiredInstance.sub(time.Now())` is different depending on whether `clock.AdvanceBy` finishes
60+ // before or after the timer reset.
5361func (c * MockClock ) InstantTimer (when time.Time ) * mockInstantTimer {
5462 c .mu .Lock ()
5563 defer c .mu .Unlock ()
You can’t perform that action at this time.
0 commit comments