nodedb_types/fail_point/mod.rs
1// SPDX-License-Identifier: Apache-2.0
2
3//! Minimal feature-gated fail-point framework for crash-injection tests.
4//!
5//! When the `failpoints` Cargo feature is OFF (the default and what release
6//! builds compile with), `fail_point!` expands to nothing at runtime.
7//!
8//! When the feature is ON, each invocation looks up its scope and name in a
9//! process-wide registry. A point evaluated with scope `Node(n)` fires the
10//! action armed for `(Node(n), name)`, else the one armed for `(Any, name)`.
11//! A point evaluated with scope `Any` fires only the `(Any, name)` action.
12//! The actions are listed on [`FailAction`].
13//!
14//! An in-process cluster test runs several nodes in one process, so they
15//! share the registry. The scope arms one node's point and leaves the
16//! others running.
17//!
18//! Tests arm actions with `set` / `clear` or the RAII [`FailGuard`]. A
19//! spawned server reads its actions once from [`FAILPOINTS_ENV`].
20//!
21//! Feature gating is per-crate: the macros expand under the *calling* crate's
22//! `failpoints` feature, so every crate that injects a fail point declares its
23//! own `failpoints = ["nodedb-types/failpoints"]`.
24
25#[cfg(feature = "failpoints")]
26pub mod action;
27#[cfg(feature = "failpoints")]
28pub mod env;
29#[cfg(feature = "failpoints")]
30pub mod guard;
31pub mod macros;
32#[cfg(feature = "failpoints")]
33pub mod registry;
34pub mod scope;
35
36#[cfg(feature = "failpoints")]
37pub use action::FailAction;
38#[cfg(feature = "failpoints")]
39pub use env::FAILPOINTS_ENV;
40#[cfg(feature = "failpoints")]
41pub use guard::FailGuard;
42#[cfg(feature = "failpoints")]
43pub use registry::{clear, eval, eval_fail, lookup, set};
44pub use scope::FailScope;