Skip to main content

Module statement_failure

Module statement_failure 

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

InjectedFailure
Error returned by maybe_fail_statement / maybe_fail_commit when 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 f with a one-shot commit failure armed. Injection is automatically disabled after the closure returns.
with_statement_failure_after
Run f with statement injection armed to fire on the fail_after-th call to maybe_fail_statement. Injection is automatically disabled after the closure returns.