SimulationBuilder

Struct SimulationBuilder 

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

Builder pattern for configuring and running simulation experiments.

Implementations§

Source§

impl SimulationBuilder

Source

pub fn new() -> Self

Create a new empty simulation builder.

Source

pub fn register_workload<S, F, Fut>(self, name: S, workload: F) -> Self

Register a workload with the simulation builder.

§Arguments
  • name - Name for the workload (for reporting purposes)
  • workload - Async function that takes a RandomProvider, NetworkProvider, TimeProvider, TaskProvider, and WorkloadTopology and returns simulation metrics
Source

pub fn set_iterations(self, iterations: usize) -> Self

Set the number of iterations to run.

Source

pub fn set_iteration_control(self, control: IterationControl) -> Self

Set the iteration control strategy.

Source

pub fn set_time_limit(self, duration: Duration) -> Self

Run for a specific wall-clock time duration.

Source

pub fn run_until_all_sometimes_reached(self, safety_limit: usize) -> Self

Run until all sometimes_assert! assertions have been reached.

Source

pub fn set_debug_seeds(self, seeds: Vec<u64>) -> Self

Set specific seeds for deterministic debugging and regression testing.

This method is specifically designed for debugging scenarios where you need to reproduce specific problematic behavior. Unlike set_seeds(), the name makes it clear this is for debugging/testing specific scenarios.

Key differences from set_seeds():

  • Intent: Clearly indicates debugging/testing purpose
  • Usage: Typically used with FixedCount(1) for reproducing exact scenarios
  • Documentation: Self-documenting that these seeds are for specific test cases

Common use cases:

  • Reproducing TCP ordering bugs (e.g., seed 42 revealed the ordering issue)
  • Regression testing for specific edge cases
  • Deterministic testing in CI/CD pipelines
  • Investigating assertion failures at specific seeds

Example: set_debug_seeds(vec![42]) with FixedCount(1) ensures the test always runs with seed 42, making it reproducible for debugging the TCP ordering fix.

Source

pub fn use_random_config(self) -> Self

Enable randomized network configuration for chaos testing

Source

pub fn with_invariants(self, invariants: Vec<InvariantCheck>) -> Self

Register invariant check functions to be executed after every simulation event.

Invariants receive a snapshot of all actor states and the current simulation time, and should panic if any global property is violated.

§Arguments
  • invariants - Vector of invariant check functions
§Example
SimulationBuilder::new()
    .with_invariants(vec![
        Box::new(|states, _time| {
            let total_sent: u64 = states.values()
                .filter_map(|v| v.get("messages_sent").and_then(|s| s.as_u64()))
                .sum();
            let total_received: u64 = states.values()
                .filter_map(|v| v.get("messages_received").and_then(|r| r.as_u64()))
                .sum();
            assert!(total_received <= total_sent, "Message conservation violated");
        })
    ])
Source

pub async fn run(self) -> SimulationReport

Run the simulation and generate a report.

Trait Implementations§

Source§

impl Default for SimulationBuilder

Source§

fn default() -> Self

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

Auto Trait Implementations§

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more