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