Expand description
Statement / commit failure injection for testing rollback paths.
When the testing-statement-injection feature is enabled,
maybe_fail_statement counts down a thread-local counter and returns
InjectedFailure when it reaches zero. maybe_fail_commit returns
InjectedFailure once if a commit trigger is armed.
Unlike crash (which panics), injection returns an error
so the session’s normal error path runs. This matches how real runtime
errors (constraint violations, parse errors) behave: the transaction stays
active and the caller is expected to issue ROLLBACK explicitly.
Thread-local storage ensures concurrent tests never interfere with each
other; only the thread that calls enable_statement_failure_after /
enable_commit_failure_once is affected.
When the feature is disabled, all functions compile to no-ops with zero runtime overhead.
§Example
use grafeo_common::testing::statement_failure::with_statement_failure_after;
with_statement_failure_after(3, || {
// 1st and 2nd calls to maybe_fail_statement succeed.
// 3rd returns Err(InjectedFailure).
});Structs§
- Injected
Failure - Error returned by
maybe_fail_statement/maybe_fail_commitwhen the injection fires. Tests match on this via the session’s error chain.
Functions§
- disable_
injection - No-op when injection is disabled.
- enable_
commit_ failure_ once - No-op when injection is disabled.
- enable_
statement_ failure_ after - No-op when injection is disabled.
- maybe_
fail_ commit - No-op when injection is disabled.
- maybe_
fail_ statement - No-op when injection is disabled.
- with_
commit_ failure - Run
fwith a one-shot commit failure armed. Injection is automatically disabled after the closure returns. - with_
statement_ failure_ after - Run
fwith statement injection armed to fire on thefail_after-th call tomaybe_fail_statement. Injection is automatically disabled after the closure returns.