internal/clocktest
import "github.com/gofiber/fiber/v3/internal/clocktest"
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.
Functions
func NewClock(start time.Time) *Clock
Source: internal/clocktest/clocktest.go:55
NewClock returns a Clock that reads start until it is advanced.
func SleepPast(tb testing.TB, ttl time.Duration)
Source: internal/clocktest/clocktest.go:22
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
Source: internal/clocktest/clocktest.go:45
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.
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
}Fields
Step time.DurationStep, 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.
func (c *Clock) Add(d time.Duration)
Source: internal/clocktest/clocktest.go:66
Add moves the clock forward by d.
func (c *Clock) Now() time.Time
Source: internal/clocktest/clocktest.go:58
Now advances the clock by Step and returns the time it then reads.