Struct Builder

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

A builder that can be used to configure the simulation.

The Builder allows you to set a number of options when creating a turmoil simulation, see the available methods for documentation of each of these options.

§Examples

You can use the builder to initialize a sim with default configuration:

let sim = turmoil::Builder::new().build();

If you want to vary factors of the simulation, you can use the respective Builder methods:

use std::time::{Duration, SystemTime};

let sim = turmoil::Builder::new()
    .simulation_duration(Duration::from_secs(60))
    .epoch(SystemTime::UNIX_EPOCH.checked_add(Duration::from_secs(946684800)).unwrap())
    .fail_rate(0.05) // 5% failure rate
    .build();

If you create a builder with a set of options you can then repeatedly call build to get a sim with the same settings:

use std::time::Duration;

// Create a persistent builder
let mut builder = turmoil::Builder::new();

// Apply a chain of options to that builder
builder.simulation_duration(Duration::from_secs(45))
    .fail_rate(0.05);

let sim_one = builder.build();
let sim_two = builder.build();

§Entropy and randomness

By default, the builder will use its own rng to determine the variation in random factors that affect the simulation, like message latency, and failure distributions. To make your tests deterministic, you can use your own seeded rng provider when building the simulation through build_with_rng.

For example:

use rand::rngs::SmallRng;
use rand::SeedableRng;

let rng = SmallRng::seed_from_u64(0);
let sim = turmoil::Builder::new().build_with_rng(Box::new(rng));

Implementations§

Source§

impl Builder

Source

pub fn new() -> Self

Source

pub fn epoch(&mut self, value: SystemTime) -> &mut Self

When the simulation starts.

Source

pub fn simulation_duration(&mut self, value: Duration) -> &mut Self

How long the test should run for in simulated time

Source

pub fn tick_duration(&mut self, value: Duration) -> &mut Self

How much simulated time should elapse each tick.

Source

pub fn ip_version(&mut self, value: IpVersion) -> &mut Self

Which kind of network should be simulated.

Source

pub fn min_message_latency(&mut self, value: Duration) -> &mut Self

The minimum latency that a message will take to transfer over a link on the network.

Source

pub fn max_message_latency(&mut self, value: Duration) -> &mut Self

The maximum latency that a message will take to transfer over a link on the network.

Source

pub fn fail_rate(&mut self, value: f64) -> &mut Self

The failure rate of messages on the network. For TCP this will break connections as currently there are no re-send capabilities. With UDP this is useful for testing network flakiness.

Source

pub fn repair_rate(&mut self, value: f64) -> &mut Self

The repair rate of messages on the network. This is how frequently a link is repaired after breaking.

Source

pub fn ephemeral_ports(&mut self, value: RangeInclusive<u16>) -> &mut Self

The Dynamic Ports, also known as the Private or Ephemeral Ports. See: https://www.rfc-editor.org/rfc/rfc6335#section-6

Source

pub fn tcp_capacity(&mut self, value: usize) -> &mut Self

Capacity of a host’s TCP buffer in the sim.

Source

pub fn udp_capacity(&mut self, value: usize) -> &mut Self

Capacity of host’s UDP buffer in the sim.

Source

pub fn enable_tokio_io(&mut self) -> &mut Self

Enables the tokio I/O driver.

Source

pub fn enable_random_order(&mut self) -> &mut Self

Enables running of nodes in random order. This allows exploration of extra state space in multi-node simulations where race conditions may arise based on message send/receive order.

Source

pub fn build<'a>(&self) -> Sim<'a>

Build a simulation with the settings from the builder.

This will use default rng with entropy from the device running.

Source

pub fn build_with_rng<'a>(&self, rng: Box<dyn RngCore>) -> Sim<'a>

Build a sim with a provided rng.

This allows setting the random number generator used to fuzz

Trait Implementations§

Source§

impl Default for Builder

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