Documentation
¶
Overview ¶
Package clock is the only place permitted to read wall-clock time. Everything else takes a Clock so tests can drive time deterministically.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Clock ¶
type Clock interface {
Now() time.Time
// AfterFunc runs f once, d in the future; a non-positive d is due now.
// f runs on an unspecified goroutine, or synchronously inside Advance.
AfterFunc(d time.Duration, f func()) Timer
}
Clock is the emulator's sole source of time.
type FakeClock ¶
type FakeClock struct {
// contains filtered or unexported fields
}
FakeClock is a Clock whose time only moves when a test moves it. It never sleeps and never polls.
func NewFakeNow ¶
func NewFakeNow() *FakeClock
NewFakeNow returns a FakeClock seeded at the real wall-clock time. A manual-mode server uses it so timestamps start realistic, then hold still until a client advances the clock. Reading time.Now here is the point: this is the one hand-off from the wall clock into a clock the emulator controls.
func (*FakeClock) Advance ¶
Advance moves time forward by d, running every callback that comes due in timestamp order and draining past d. Reentrant calls panic.
func (*FakeClock) AdvanceTo ¶
AdvanceTo moves time forward to target, running every callback that comes due, and reports whether the target was reachable. It returns false only when target is strictly before now, since time does not move backward; target equal to now is a no-op that still reports true. The comparison and the move happen under one lock, so a caller cannot be told the target is in the future and then have a concurrent jump move past it — concurrent absolute travel converges on the latest target instead of summing deltas or falsely succeeding on a stale check.