Skip to main content

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 workload(self, w: impl Workload) -> Self

Add a single workload instance to the simulation.

The instance is reused across iterations (the run() method is called each iteration on the same struct).

Source

pub fn workloads( self, count: WorkloadCount, factory: impl Fn(usize) -> Box<dyn Workload> + 'static, ) -> Self

Add multiple workload instances from a factory.

The factory receives an instance index (0-based) and must return a fresh workload. Instances are created each iteration and dropped afterward.

The workload is responsible for its own name() — use the index to produce unique names when count > 1 (e.g., format!("client-{i}")).

§Examples
// 3 fixed replicas
builder.workloads(WorkloadCount::Fixed(3), |i| Box::new(ReplicaWorkload::new(i)))

// 1–5 random clients
builder.workloads(WorkloadCount::Random(1..6), |i| Box::new(ClientWorkload::new(i)))
Source

pub fn invariant(self, i: impl Invariant) -> Self

Add an invariant to be checked after every simulation event.

Source

pub fn invariant_fn( self, name: impl Into<String>, f: impl Fn(&StateHandle, u64) + 'static, ) -> Self

Add a closure-based invariant.

Source

pub fn fault(self, f: impl FaultInjector) -> Self

Add a fault injector to run during the chaos phase.

Source

pub fn phases(self, config: PhaseConfig) -> Self

Set two-phase chaos/recovery configuration.

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 set_debug_seeds(self, seeds: Vec<u64>) -> Self

Set specific seeds for deterministic debugging and regression testing.

Source

pub fn random_network(self) -> Self

Enable randomized network configuration for chaos testing.

Source

pub fn enable_exploration(self, config: ExplorationConfig) -> Self

Enable fork-based multiverse exploration.

When enabled, the simulation will fork child processes at assertion discovery points to explore alternate timelines with different seeds.

Source

pub fn replay_recipe(self, recipe: BugRecipe) -> Self

Set a bug recipe for deterministic replay.

The builder applies the recipe’s RNG breakpoints after its own initialization, ensuring they survive internal resets.

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§

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> 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
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 = Infallible

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

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

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.
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