| Crates.io | chaos-rs |
| lib.rs | chaos-rs |
| version | 0.1.4 |
| created_at | 2025-07-30 13:43:40.826339+00 |
| updated_at | 2025-07-30 14:07:33.220513+00 |
| description | Minimal library for chaos testing |
| homepage | |
| repository | https://github.com/ConeDjordjic/chaos-rs |
| max_upload_size | |
| id | 1773547 |
| size | 18,386 |
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.
Add to your Cargo.toml:
[dependencies]
chaos-rs = "0.1.4"
Inject failures:
fn do_work() -> Result<&'static str, String> {
chaos_rs::maybe_fail!("db_error", "Database connection failed".into());
Ok("success")
}
Simulate panics:
fn critical_section() {
chaos_rs::maybe_panic!("unexpected_panic");
// ... critical code
}
Add delays:
fn slow_operation() {
chaos_rs::maybe_sleep!("slow_io", 500);
// ... operation
}
async fn async_operation() {
chaos_rs::maybe_sleep_async!("slow_async", 200);
// ... async operation
}
#[test]
fn test_error_handling() {
chaos_rs::with_failpoint!("db_error", error, do_work());
}
#[test]
fn test_panic_handling() {
chaos_rs::with_failpoint!("unexpected_panic", panic, {
critical_section();
});
}
#[test]
fn test_timing() {
chaos_rs::with_failpoint!("slow_io", 500, 50, {
slow_operation(); // Should sleep 450-550ms
});
}
MIT