Documentation
¶
Overview ¶
Package clocktest lets tests wait on the cached, second-granularity clock that fiber's memory storages and rate-limit windows are measured against, and provides a manually advanced clock for code that takes its time source.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SleepPast ¶
SleepPast waits out ttl in wall time and then blocks until utils.Timestamp() has advanced by ttl truncated to whole seconds, the granularity the storages compare expiry against.
Expiry is compared against that cached timestamp, and the goroutine refreshing it once per second can be scheduled well over a second late on a loaded machine, so a wall-clock sleep alone leaves entries live past their TTL often enough to turn CI red.
Types ¶
type Clock ¶ added in v3.7.0
type Clock struct {
// Step, when set before the clock is shared, is added to the clock on every
// Now, so a read of the clock the code under test did not need shows up as
// elapsed time.
Step time.Duration
// contains filtered or unexported fields
}
Clock is a manually advanced clock, safe for the concurrent reads a handler performs. Tests that depend on a TTL or window boundary advance it with Add instead of sleeping past the boundary, which is racy under -race and -shuffle. Hand its Now method to the code under test as the time source.