pub struct Clock { /* private fields */ }Expand description
Virtual milliseconds since the mock started.
speed is how many virtual milliseconds pass per real millisecond, so 1.0
is real time. At 0.0 real time contributes nothing and the clock only
moves when something [Clock::advance]s it — which the request handlers do,
by the smallest amount that lets the next scheduled transition happen. That
is what makes a storm run at CPU speed without reordering anything.
Implementations§
Source§impl Clock
impl Clock
Sourcepub fn new(speed_milli: u64) -> Clock
pub fn new(speed_milli: u64) -> Clock
speed in thousandths, so the knob is an integer and two mocks with the
same knob are the same mock. 1000 = real time, 0 = virtual only.
pub fn faithful() -> Clock
pub fn virtual_only() -> Clock
pub fn speed_milli(&self) -> u64
Sourcepub fn advance_ms(&self, ms: u64)
pub fn advance_ms(&self, ms: u64)
Push the virtual clock forward. Used by the handlers when speed_milli
is 0.
This sentence used to say the wrong thing, and it cost an afternoon.
It claimed a read of an object mid-transition “advances time to the
moment the transition completes, so the SECOND poll sees it done”.
Estate::tick does no such thing and says so in its own comment: it
advances HALFWAY to the next deadline, on purpose, so that a client must
poll several times as it does against the provider. Halving a 12 000 ms
stop takes about FOURTEEN polls to close.
That is fine for a client with its own loop and fatal for one with a
BUDGET: MEASURED 2026-09-21, UpCloudLtd/upcloud 5.44.1 waiting for a
server to reach stopped before a filesystem resize gave up while the
mock still said maintenance, and the resize was then refused
SERVER_STATE_ILLEGAL — a defect that belongs to neither the estate nor
the provider. Drive terraform against a mock with a non-zero
--speed (20 000 is 20× faster than the account and still real
waiting); --speed 0 is for in-process callers that poll without a
wall-clock budget.
Sourcepub fn real_wait_for(&self, at_ms: u64) -> Option<Duration>
pub fn real_wait_for(&self, at_ms: u64) -> Option<Duration>
The gap the mock should let a caller experience for a scheduled at_ms.
At real speed this is a real sleep; at virtual speed it is nothing, and
the caller is expected to Clock::advance_ms instead.