Documentation ¶
Index ¶
- type Clock
- type MockClock
- func (mc *MockClock) Advance(duration time.Duration)
- func (mc *MockClock) After(duration time.Duration) <-chan time.Time
- func (mc *MockClock) BlockedOnAfter() int
- func (mc *MockClock) BlockingAdvance(duration time.Duration)
- func (mc *MockClock) GetAfterArgs() []time.Duration
- func (mc *MockClock) GetTickerArgs() []time.Duration
- func (mc *MockClock) NewTicker(duration time.Duration) Ticker
- func (mc *MockClock) Now() time.Time
- func (mc *MockClock) SetCurrent(current time.Time)
- func (mc *MockClock) Since(t time.Time) time.Duration
- func (mc *MockClock) Sleep(duration time.Duration)
- func (mc *MockClock) Until(t time.Time) time.Duration
- type Ticker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Clock ¶
type Clock interface { // Now returns the current time. Now() time.Time // After returns a channel which receives the current time after // the given duration elapses. After(duration time.Duration) <-chan time.Time // Sleep blocks until the given duration elapses. Sleep(duration time.Duration) // Since returns the time elapsed since t. Since(t time.Time) time.Duration // Until returns the duration until t. Until(t time.Time) time.Duration // NewTicker will construct a ticker which will continually fire, // pausing for the given duration in between invocations. NewTicker(duration time.Duration) Ticker }
Clock is a wrapper around common functions in the time package. This interface is designed to allow easy mocking of time functions.
func NewRealClock ¶
func NewRealClock() Clock
NewRealClock returns a Clock whose implementation falls back to the methods available in the time package.
type MockClock ¶
type MockClock struct {
// contains filtered or unexported fields
}
MockClock is an implementation of Clock that can be moved forward in time in increments for testing code that relies on timeouts or other time-sensitive constructs.
func NewMockClock ¶
func NewMockClock() *MockClock
NewMockClock creates a new MockClock with the internal time set to time.Now()
func NewMockClockAt ¶
NewMockClockAt creates a new MockClick with the internal time set to the provided time.
func (*MockClock) After ¶
After returns a channel that will be sent the current internal MockClock time once the MockClock's internal time is at or past the provided duration
func (*MockClock) BlockedOnAfter ¶
BlockedOnAfter returns the number of calls to After that are blocked waiting for a call to Advance to trigger them.
func (*MockClock) BlockingAdvance ¶
BlockingAdvance will call Advance but only after there is another routine which is blocking on the channel result of a call to After.
func (*MockClock) GetAfterArgs ¶
GetAfterArgs returns the duration of each call to After in the same order as they were called. The list is cleared each time GetAfterArgs is called.
func (*MockClock) GetTickerArgs ¶
GetTickerArgs returns the duration of each call to create a new ticker in the same order as they were called. The list is cleared each time GetTickerArgs is called.
func (*MockClock) NewTicker ¶
NewTicker creates a new Ticker tied to the internal MockClock time that ticks at intervals similar to time.NewTicker(). It will also skip or drop ticks for slow readers similar to time.NewTicker() as well.
func (*MockClock) SetCurrent ¶
SetCurrent sets the internal MockClock time to the supplied time.
type Ticker ¶
type Ticker interface { // Chan returns the underlying ticker channel. Chan() <-chan time.Time // Stop stops the ticker. Stop() }
Ticker is a wrapper around a time.Ticker, which allows interface access to the underlying channel (instead of bare access like the time.Ticker struct allows).