pub struct TestSimulator { /* private fields */ }Expand description
A deterministic test-only execution environment around one Driver.
Implementations§
Source§impl TestSimulator
impl TestSimulator
Sourcepub fn wall_clock(&self, epoch: SystemTime) -> TestWallClock
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
impl TestSimulator
Sourcepub fn receipt(&self) -> ScenarioReceipt
pub fn receipt(&self) -> ScenarioReceipt
Creates an empty, stable receipt for one test scenario.
Source§impl TestSimulator
impl TestSimulator
Sourcepub fn gate(&self, name: impl Into<String>) -> SimulatorGate
pub fn gate(&self, name: impl Into<String>) -> SimulatorGate
Creates a named cooperative checkpoint for one test scenario.
Sourcepub fn resource(&self, name: impl Into<String>) -> SimulatorResource
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.
Sourcepub fn faults(&self) -> FaultInjector
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.
Sourcepub fn run<F: Future>(&self, future: F) -> F::Output
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.
Sourcepub fn pump(&self)
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.
Sourcepub fn spawn<F>(&self, future: F) -> Result<DriverTask, SpawnError>
pub fn spawn<F>(&self, future: F) -> Result<DriverTask, SpawnError>
Spawns voluntary scenario work on the deterministic local lane.
Sourcepub fn advance(&self, duration: Duration)
pub fn advance(&self, duration: Duration)
Advances virtual time and wakes elapsed deterministic timers.
Sourcepub fn sleep_until(&self, deadline: Duration) -> LocalBoxFuture<'static, ()>
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.
Sourcepub fn driver(&self) -> DeterministicDriver
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.