Documentation ¶
Overview ¶
Package mclock is a wrapper for a monotonic clock source
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Clock ¶
Clock interface makes it possible to replace the monotonic system clock with a simulated clock.
type Simulated ¶
type Simulated struct {
// contains filtered or unexported fields
}
Simulated implements a virtual Clock for reproducible time-sensitive tests. It simulates a scheduler on a virtual timescale where actual processing takes zero time.
The virtual clock doesn't advance on its own, call Run to advance it and execute timers. Since there is no way to influence the Go scheduler, testing timeout behaviour involving goroutines needs special care. A good way to test such timeouts is as follows: First perform the action that is supposed to time out. Ensure that the timer you want to test is created. Then run the clock until after the timeout. Finally observe the effect of the timeout using a channel or semaphore.
func (*Simulated) ActiveTimers ¶
func (*Simulated) Run ¶
Run moves the clock by the given duration, executing all timers before that duration.