Skip to main content

TestSimulator

Struct TestSimulator 

Source
pub struct TestSimulator { /* private fields */ }
Expand description

A deterministic test-only execution environment around one Driver.

Implementations§

Source§

impl TestSimulator

Source

pub fn wall_clock(&self, epoch: SystemTime) -> TestWallClock

Projects this simulator’s virtual monotonic clock onto a chosen epoch.

The supplied epoch is part of the test scenario, not Host configuration or production security policy.

Source§

impl TestSimulator

Source

pub fn receipt(&self) -> ScenarioReceipt

Creates an empty, stable receipt for one test scenario.

Source§

impl TestSimulator

Source

pub fn new() -> Self

Creates a Simulator at virtual monotonic instant zero.

Source

pub fn gate(&self, name: impl Into<String>) -> SimulatorGate

Creates a named cooperative checkpoint for one test scenario.

Source

pub fn resource(&self, name: impl Into<String>) -> SimulatorResource

Creates a cooperative, test-owned resource availability control.

Unlike a SimulatorGate, a resource may be frozen and thawed more than once. Scenario code opts in by awaiting SimulatorResource::acquire at the same private resource boundary it uses in production; the simulator never substitutes a second business implementation.

Source

pub fn faults(&self) -> FaultInjector

Returns this Simulator’s test-owned, explicit fault injector.

Injected failures stay inert until scenario code checks the exact boundary. This avoids turning target behavior into an implicit global fault policy.

Source

pub fn run<F: Future>(&self, future: F) -> F::Output

Runs one root future on the deterministic Driver.

This must remain the outermost Driver run for a scenario. Calling it from a future already running on this Simulator is recursive and is rejected by the underlying Driver.

Source

pub fn pump(&self)

Cooperatively drives currently runnable local work.

A pump is a scheduling boundary, not a single-step scheduler: the underlying local executor may poll more than one ready future before this call returns. Call it only outside a running Self::run future.

Source

pub fn spawn<F>(&self, future: F) -> Result<DriverTask, SpawnError>
where F: Future<Output = ()> + 'static,

Spawns voluntary scenario work on the deterministic local lane.

Source

pub fn advance(&self, duration: Duration)

Advances virtual time and wakes elapsed deterministic timers.

Source

pub fn now(&self) -> Duration

Returns the current virtual monotonic instant.

Source

pub fn sleep_until(&self, deadline: Duration) -> LocalBoxFuture<'static, ()>

Waits until a virtual monotonic instant on this Simulator’s Driver.

Deadlines use the same time origin as Self::now. An elapsed deadline completes immediately; a future deadline requires Self::advance and polling the waiting work, for example with Self::pump. Sleeping never advances time automatically. The returned future owns its wait and can be moved into a Plugin or a spawned task without borrowing the Simulator.

Source

pub fn driver(&self) -> DeterministicDriver

Returns the same Driver for generated Host lowering and facility clocks. External processes and I/O are not virtualized by this Driver.

Trait Implementations§

Source§

impl Clone for TestSimulator

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TestSimulator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TestSimulator

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.