Skip to main content

Module clock

Module clock 

Source
Expand description

Deterministic time-skew injection for testing time-sensitive code.

Code that retries on timeout, expires sessions, schedules futures, or compares timestamps depends on a clock. Clock is a source of Instant-ish values that the caller controls explicitly: you advance it with Clock::advance or skew it with Clock::skew_by to validate that retry loops, expiry checks, and TTL logic behave correctly without std::thread::sleep.

§Determinism

Clock is fully deterministic: the same sequence of advance and now calls produces the same sequence of values across runs and machines. No system calls, no thread sleeps.

§Pairing with std::time::Instant

Instant is opaque and cannot be constructed directly, so this module uses an offset-from-anchor model. Clock::now returns a ClockTime (just a Duration from anchor); the caller adapts this to their domain. For callers that need an Instant, see Clock::anchor and add the offset.

Structs§

Clock
Deterministic, in-process clock for chaos testing.
ClockTime
A virtual time value measured as a Duration since the clock’s anchor.