[control] Test hooks: IANITOR_TEST_CRASH_AT and IANITOR_TEST_FAIL_WRITE only with the default test-hooks feature; a --no-default-features build has neither
This commit is contained in:
@@ -15,6 +15,12 @@ path = "src/lib.rs"
|
|||||||
name = "ianitor-control"
|
name = "ianitor-control"
|
||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
# The crash and write-failure hooks of the crash-safety tests (src/crash.rs). The Nix release
|
||||||
|
# build turns them off with --no-default-features.
|
||||||
|
default = ["test-hooks"]
|
||||||
|
test-hooks = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ianitor-core.workspace = true
|
ianitor-core.workspace = true
|
||||||
axum = { version = "0.8.9", default-features = false, features = ["http1", "json", "query", "tokio", "matched-path"] }
|
axum = { version = "0.8.9", default-features = false, features = ["http1", "json", "query", "tokio", "matched-path"] }
|
||||||
|
|||||||
@@ -4,10 +4,13 @@
|
|||||||
|
|
||||||
//! Crash points for the crash-safety tests: with `IANITOR_TEST_CRASH_AT=<stage>` in its
|
//! Crash points for the crash-safety tests: with `IANITOR_TEST_CRASH_AT=<stage>` in its
|
||||||
//! environment, control aborts (no cleanup, like a kill -9) when an apply reaches that stage.
|
//! environment, control aborts (no cleanup, like a kill -9) when an apply reaches that stage.
|
||||||
//! Without the variable this does nothing; the NixOS unit never sets it.
|
|
||||||
//!
|
//!
|
||||||
//! `IANITOR_TEST_FAIL_WRITE=<file name>` makes every write of a state file with that name
|
//! `IANITOR_TEST_FAIL_WRITE=<file name>` makes every write of a state file with that name
|
||||||
//! fail, as on a full disk (fault injection for the same tests).
|
//! fail, as on a full disk (fault injection for the same tests).
|
||||||
|
//!
|
||||||
|
//! Both exist only with the `test-hooks` cargo feature (on by default, so `cargo test` has
|
||||||
|
//! them). The release build (`nix build .#ianitor`) is built with `--no-default-features`:
|
||||||
|
//! there these functions do nothing and read no environment variable.
|
||||||
|
|
||||||
/// The stages, in order.
|
/// The stages, in order.
|
||||||
pub const STAGES: [&str; 9] = [
|
pub const STAGES: [&str; 9] = [
|
||||||
@@ -22,6 +25,10 @@ pub const STAGES: [&str; 9] = [
|
|||||||
"reverting",
|
"reverting",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/// Whether this binary has the test hooks.
|
||||||
|
pub const ENABLED: bool = cfg!(feature = "test-hooks");
|
||||||
|
|
||||||
|
#[cfg(feature = "test-hooks")]
|
||||||
pub fn point(stage: &str) {
|
pub fn point(stage: &str) {
|
||||||
if std::env::var("IANITOR_TEST_CRASH_AT").as_deref() == Ok(stage) {
|
if std::env::var("IANITOR_TEST_CRASH_AT").as_deref() == Ok(stage) {
|
||||||
log::error!(target: "ianitor::crash", "IANITOR_TEST_CRASH_AT={stage}: aborting on purpose");
|
log::error!(target: "ianitor::crash", "IANITOR_TEST_CRASH_AT={stage}: aborting on purpose");
|
||||||
@@ -29,7 +36,12 @@ pub fn point(stage: &str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "test-hooks"))]
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn point(_stage: &str) {}
|
||||||
|
|
||||||
/// Fail a state-file write when `IANITOR_TEST_FAIL_WRITE` names this file.
|
/// Fail a state-file write when `IANITOR_TEST_FAIL_WRITE` names this file.
|
||||||
|
#[cfg(feature = "test-hooks")]
|
||||||
pub fn fail_write(path: &std::path::Path) -> Result<(), String> {
|
pub fn fail_write(path: &std::path::Path) -> Result<(), String> {
|
||||||
match (
|
match (
|
||||||
std::env::var_os("IANITOR_TEST_FAIL_WRITE"),
|
std::env::var_os("IANITOR_TEST_FAIL_WRITE"),
|
||||||
@@ -42,3 +54,9 @@ pub fn fail_write(path: &std::path::Path) -> Result<(), String> {
|
|||||||
_ => Ok(()),
|
_ => Ok(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "test-hooks"))]
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn fail_write(_path: &std::path::Path) -> Result<(), String> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user