Documentation ¶
Index ¶
- type AdvanceableClock
- type AutoAdvancingClock
- type Clock
- func (clock *Clock) Advance(d time.Duration)
- func (clock *Clock) After(d time.Duration) <-chan time.Time
- func (clock *Clock) AfterFunc(d time.Duration, f func()) clock.Timer
- func (clock *Clock) Alarms() <-chan struct{}
- func (clock *Clock) NewTimer(d time.Duration) clock.Timer
- func (clock *Clock) Now() time.Time
- func (clock *Clock) WaitAdvance(d, w time.Duration, n int) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AdvanceableClock ¶ added in v1.0.1
AdvanceableClock is a clock that can be advanced to trigger timers/trigger timers earlier than they would otherwise.
func NewDilatedWallClock ¶
func NewDilatedWallClock(realSecondDuration time.Duration) AdvanceableClock
NewDilatedWallClock returns a clock that can be sped up or slowed down. realSecondDuration is the real duration of a second.
type AutoAdvancingClock ¶
AutoAdvancingClock wraps a clock.Clock, calling the Advance function whenever After or AfterFunc are called.
type Clock ¶
type Clock struct {
// contains filtered or unexported fields
}
Clock implements a mock clock.Clock for testing purposes.
func NewClock ¶
NewClock returns a new clock set to the supplied time. If your SUT needs to call After, AfterFunc, NewTimer or Timer.Reset more than 10000 times: (1) you have probably written a bad test; and (2) you'll need to read from the Alarms chan to keep the buffer clear.
func (*Clock) Advance ¶
Advance advances the result of Now by the supplied duration, and sends the "current" time on all alarms which are no longer "in the future".
func (*Clock) Alarms ¶
func (clock *Clock) Alarms() <-chan struct{}
Alarms returns a channel on which you can read one value for every call to After and AfterFunc; and for every successful Timer.Reset backed by this Clock. It might not be elegant but it's necessary when testing time logic that runs on a goroutine other than that of the test.
func (*Clock) WaitAdvance ¶
WaitAdvance functions the same as Advance, but only if there is n timers in clock.waiting. This came about while fixing lp:1607044 intermittent failures. It turns out that testing.Clock.Advance might advance the time and trigger notifications before triggers are set. So we wait a limited time 'w' for 'n' timers to show up in clock.waiting, and if they do we advance 'd'.