Skip to main content

Crate dev_chaos

Crate dev_chaos 

Source
Expand description

§dev-chaos

Failure injection and recovery testing for Rust. Part of the dev-* verification suite.

Most code is tested only on the happy path. Real systems fail through partial writes, crashes, timeouts, corrupt data, and broken connections. dev-chaos provides primitives for injecting those failures on purpose, then verifying that recovery logic does its job.

§Quick example

use dev_chaos::{FailureSchedule, FailureMode};

// Fail on the 3rd, 7th, and 10th attempt.
let schedule = FailureSchedule::on_attempts(&[3, 7, 10], FailureMode::IoError);

for attempt in 1..=12 {
    match schedule.maybe_fail(attempt) {
        Ok(()) => { /* operation proceeds */ }
        Err(_e) => { /* recovery path */ }
    }
}

§Modules

  • io — sync IO wrappers (ChaosReader, ChaosWriter, ChaosFile).
  • latency — non-failing slowdowns via LatencyInjector.
  • crash — write-truncation via CrashPoint.
  • async_io (feature async-io) — tokio::io equivalents (visible in rustdoc when the feature is enabled).

§Determinism

All schedules are deterministic by default: the same sequence of attempts MUST produce the same sequence of failures across runs and machines. Probabilistic schedules (FailureSchedule::seeded_random) are opt-in, seeded, and reproducible from the seed.

Modules§

async_ioasync-io
Async IO wrappers. Available with the async-io feature.
crash
Crash-point markers that truncate writes at a known byte offset.
io
Synchronous IO wrappers that inject failures into real Read/Write types.
latency
Latency injection: simulate slow-but-not-failing operations.

Structs§

ChaosProducer
Producer wrapper that runs a chaos suite and emits a Report with each scenario’s CheckResult.
FailureSchedule
A schedule that decides whether a given attempt fails.
InjectedFailure
An error returned by injected failures.

Enums§

FailureMode
A type of failure that can be injected.

Functions§

assert_recovered
Verify that recovery logic succeeded after a failure schedule.