Failure testing and incident readiness
Quick answer
Failure testing deliberately exercises expected failures in an isolated environment. Incident readiness connects those tests to clear recovery procedures, observability and ownership of actions.
Inject controlled faults
Use deterministic fakes for unavailable dependencies, timeout decisions and bounded retry budgets. Distinguish temporary errors from permanent ones, and retry side-effecting requests only when their semantics allow it. Document detection, mitigation, recovery and verification in a runbook. Never introduce faults into a production service without an approved experiment.
trait Store { fn fetch(&self) -> Result<u32, &'static str>; }struct Offline;impl Store for Offline { fn fetch(&self) -> Result<u32, &'static str> { Err("unavailable") } }fn service(s: &impl Store) -> Result<u32, &'static str> { s.fetch() }fn main() { println!("{:?}", service(&Offline)); }Expected stdout (not executed):
Err("unavailable")The service propagates failure rather than inventing a value.
fn main() { let mut attempts = 0; let result = (0..3).find_map(|_| { attempts += 1; if attempts == 2 { Some(8) } else { None } }); println!("{result:?} {attempts}");}Expected stdout (not executed):
Some(8) 2A simulated idempotent read succeeds within its budget; real retries also need deadlines and backoff.
Common mistake
Do not use unlimited retries as a recovery plan.
Try it yourself
Change the fake to fail every time and write a three-step detection and mitigation plan.
Static examples for Rust 1.85.0, edition 2024. Run them locally in a disposable project; ByteMind execution support and these outputs have not been verified.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Failure testing and incident readiness — practice quiz
Choose one answer per question. Code examples are predictions; review explanations after attempting them.
A fake storage adapter always fails in an isolated test. What should be verified?
Failure testing and incident readiness — example 1. Read the code; do not execute it for this question. Assume the lesson’s stated setup, compatible dependencies and toolchain, and a fresh disposable directory for file-creating examples. ```rust trait Store { fn fetch(&self) -> Result<u32, &'static str>; } struct Offline; impl Store for Offline { fn fetch(&self) -> Result<u32, &'static str> { Err("unavailable") } } fn service(s: &impl Store) -> Result<u32, &'static str> { s.fetch() } fn main() { println!("{:?}", service(&Offline)); } ``` What standard output should the program produce if its run succeeds? Ignore Cargo and diagnostic messages.
Failure testing and incident readiness — example 2. Read the code; do not execute it for this question. Assume the lesson’s stated setup, compatible dependencies and toolchain, and a fresh disposable directory for file-creating examples. ```rust fn main() { let mut attempts = 0; let result = (0..3).find_map(|_| { attempts += 1; if attempts == 2 { Some(8) } else { None } }); println!("{result:?} {attempts}"); } ``` What standard output should the program produce if its run succeeds? Ignore Cargo and diagnostic messages.