Crate chaos_rs

Crate chaos_rs 

Source
Expand description

§chaos_rs

Minimal chaos testing library for Rust.

chaos_rs provides macros for injecting failures, panics, and delays during testing, enabling you to validate your code’s resilience under adverse conditions.

§Features

  • Fail injection: Return errors from tagged failpoints (maybe_fail!).
  • Panic simulation: Trigger panics when failpoints are enabled (maybe_panic!).
  • Sleep injection: Add artificial delays for timing tests (maybe_sleep!) and async with (maybe_sleep_async!).
  • Assertion helpers: Verify that failpoints behave as expected (with_failpoint!) or (with_failpoint_async!) for async.

§Example

fn do_work() -> Result<&'static str, String> {
    chaos_rs::maybe_fail!("db_error", "Database connection failed".into());
    Ok("success")
}

Modules§

__failpoint_internal

Macros§

maybe_fail
Returns Err(tag.into()) or a custom error when the failpoint is enabled.
maybe_panic
Panics when the failpoint is enabled.
maybe_sleep
Sleeps for a given number of milliseconds when the failpoint is enabled.
maybe_sleep_async
If the specified failpoint is enabled, this macro will pause the asynchronous execution for a given number of milliseconds.
with_failpoint
Runs a code block with a failpoint enabled and validates its effect.
with_failpoint_async