clocktest

package
v3.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 4 Imported by: 0

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

func SleepPast(tb testing.TB, ttl time.Duration)

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.

func NewClock added in v3.7.0

func NewClock(start time.Time) *Clock

NewClock returns a Clock that reads start until it is advanced.

func (*Clock) Add added in v3.7.0

func (c *Clock) Add(d time.Duration)

Add moves the clock forward by d.

func (*Clock) Now added in v3.7.0

func (c *Clock) Now() time.Time

Now advances the clock by Step and returns the time it then reads.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL