Skip to main content

Clock

Struct Clock 

Source
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

Source

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.

Source

pub fn faithful() -> Clock

Source

pub fn virtual_only() -> Clock

Source

pub fn speed_milli(&self) -> u64

Source

pub fn now_ms(&self) -> u64

Now, in virtual milliseconds.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl !Freeze for Clock

§

impl RefUnwindSafe for Clock

§

impl Send for Clock

§

impl Sync for Clock

§

impl Unpin for Clock

§

impl UnsafeUnpin for Clock

§

impl UnwindSafe for Clock

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.