Documentation
¶
Overview ¶
Package clock is the injected time source every timeout in Agent GM is measured against (spec section 13.1). No test sleeps, and no test waits out a real 24 hours.
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
// Since is Now().Sub(t).
Since(t time.Time) time.Duration
// Sleep blocks for d as this clock measures it, or until ctx ends, in
// which case it returns ctx.Err(). Every wait in Agent GM goes through
// it -- the [3s, 8s, 20s] send backoff, ticket expiry, the pending
// timeout -- so no test sleeps and no test waits out a real 24 hours
// (spec section 13.1).
Sleep(ctx context.Context, d time.Duration) error
}
Clock is the time source.
type Fake ¶
type Fake struct {
// contains filtered or unexported fields
}
Fake advances only when a test tells it to. Two backends may share one Fake or hold two, and each test says which -- spec section 13.1's sign-out and re-pair tests advance one account's clock while the other's stands still, which is only expressible with separate clocks.
func (*Fake) FreezeSleep ¶
FreezeSleep makes Sleep record without advancing.
func (*Fake) Sleep ¶
Sleep advances this clock by d and records the wait, rather than blocking.
A fake clock that blocked until another goroutine advanced it would make every single-goroutine test a deadlock waiting to happen, and would make the thing under test -- "it backed off for 3s and then 8s" -- unobservable. Advancing and recording makes the schedule itself the assertion: see Sleeps.
A frozen clock (FreezeSleep) does not advance, for the tests that need to hold time still across a wait.