pub struct SimulationBuilder { /* private fields */ }Expand description
Builder pattern for configuring and running simulation experiments.
Implementations§
Source§impl SimulationBuilder
impl SimulationBuilder
Sourcepub fn workload(self, w: impl Workload) -> Self
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).
Sourcepub fn workloads(
self,
count: WorkloadCount,
factory: impl Fn(usize) -> Box<dyn Workload> + 'static,
) -> Self
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)))Sourcepub fn invariant(self, i: impl Invariant) -> Self
pub fn invariant(self, i: impl Invariant) -> Self
Add an invariant to be checked after every simulation event.
Sourcepub fn invariant_fn(
self,
name: impl Into<String>,
f: impl Fn(&StateHandle, u64) + 'static,
) -> Self
pub fn invariant_fn( self, name: impl Into<String>, f: impl Fn(&StateHandle, u64) + 'static, ) -> Self
Add a closure-based invariant.
Sourcepub fn fault(self, f: impl FaultInjector) -> Self
pub fn fault(self, f: impl FaultInjector) -> Self
Add a fault injector to run during the chaos phase.
Sourcepub fn phases(self, config: PhaseConfig) -> Self
pub fn phases(self, config: PhaseConfig) -> Self
Set two-phase chaos/recovery configuration.
Sourcepub fn set_iterations(self, iterations: usize) -> Self
pub fn set_iterations(self, iterations: usize) -> Self
Set the number of iterations to run.
Sourcepub fn set_iteration_control(self, control: IterationControl) -> Self
pub fn set_iteration_control(self, control: IterationControl) -> Self
Set the iteration control strategy.
Sourcepub fn set_time_limit(self, duration: Duration) -> Self
pub fn set_time_limit(self, duration: Duration) -> Self
Run for a specific wall-clock time duration.
Sourcepub fn set_debug_seeds(self, seeds: Vec<u64>) -> Self
pub fn set_debug_seeds(self, seeds: Vec<u64>) -> Self
Set specific seeds for deterministic debugging and regression testing.
Sourcepub fn random_network(self) -> Self
pub fn random_network(self) -> Self
Enable randomized network configuration for chaos testing.
Sourcepub fn enable_exploration(self, config: ExplorationConfig) -> Self
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.
Sourcepub fn replay_recipe(self, recipe: BugRecipe) -> Self
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.
Sourcepub async fn run(self) -> SimulationReport
pub async fn run(self) -> SimulationReport
Run the simulation and generate a report.