pub const ASPECT_FUNCTIONAL: &str = "functional";
#[cfg(feature = "testmatrix")]
#[inline]
pub fn emit(component: &str, check: &str, ok: bool, detail: &str) {
nornir_testmatrix::functional_status(component, check, ok, detail);
}
#[cfg(not(feature = "testmatrix"))]
#[inline]
pub fn emit(_component: &str, _check: &str, _ok: bool, _detail: &str) {}
#[macro_export]
macro_rules! assert_emit {
($component:expr, $check:expr, $ok:expr, $($detail:tt)+) => {{
let __ok: bool = $ok;
let __detail = ::std::format!($($detail)+);
$crate::selftest::emit($component, $check, __ok, &__detail);
::std::assert!(__ok, "{}::{} — {}", $component, $check, __detail);
}};
}
#[cfg(all(test, feature = "testmatrix"))]
mod wiring {
use crate::{
current_purge_delay_ms, product_purge_delay_env, purge_delay_plan, purge_delay_plan_from,
PurgeDelayPlan, DEFAULT_PURGE_DELAY_MS, MIMALLOC_V3_DEFAULT_PURGE_DELAY_MS,
};
#[test]
fn emits_honest_rows_for_allocator_surfaces() {
let shipped = current_purge_delay_ms();
assert_emit!(
"nordisk-alloc",
"shipped_default_is_v3s_1000ms",
shipped == MIMALLOC_V3_DEFAULT_PURGE_DELAY_MS,
"linked mimalloc reports purge_delay={shipped} ms"
);
let d = purge_delay_plan(None);
assert_emit!(
"nordisk-alloc",
"unset_installs_the_safe_default",
d == PurgeDelayPlan::Set(DEFAULT_PURGE_DELAY_MS),
"plan(None)={d:?}"
);
let typo = purge_delay_plan(Some("ten"));
assert_emit!(
"nordisk-alloc",
"a_typo_falls_forward_not_back",
typo == PurgeDelayPlan::Set(DEFAULT_PURGE_DELAY_MS),
"plan(\"ten\")={typo:?}"
);
let name = product_purge_delay_env("dwarves");
assert_emit!(
"nordisk-alloc",
"the_products_deployed_variable_survives_the_lift",
name == "DWARVES_MIMALLOC_PURGE_DELAY_MS",
"product_purge_delay_env(dwarves)={name}"
);
let shadow = purge_delay_plan_from(Some(""), Some("off"));
assert_emit!(
"nordisk-alloc",
"an_empty_product_value_does_not_shadow_the_fleet",
shadow == PurgeDelayPlan::LeaveAlone,
"plan_from(\"\", \"off\")={shadow:?}"
);
crate::selftest::emit(
"nordisk-alloc",
"the_installed_value_is_not_v3s_default",
DEFAULT_PURGE_DELAY_MS != MIMALLOC_V3_DEFAULT_PURGE_DELAY_MS,
&format!("installs {DEFAULT_PURGE_DELAY_MS} ms, v3 ships {MIMALLOC_V3_DEFAULT_PURGE_DELAY_MS} ms"),
);
let rows = nornir_testmatrix::drain_functional_rows();
let has = |t: &str, pass: bool| {
rows.iter().any(|r| {
r.suite == "nordisk-alloc" && r.test_name == t && (r.status == "pass") == pass
})
};
assert!(has("shipped_default_is_v3s_1000ms", true), "rows={rows:?}");
assert!(
has("unset_installs_the_safe_default", true),
"rows={rows:?}"
);
assert!(has("a_typo_falls_forward_not_back", true), "rows={rows:?}");
assert!(
has("the_products_deployed_variable_survives_the_lift", true),
"rows={rows:?}"
);
assert!(
has("an_empty_product_value_does_not_shadow_the_fleet", true),
"rows={rows:?}"
);
assert!(
has("the_installed_value_is_not_v3s_default", true),
"rows={rows:?}"
);
assert!(
rows.iter().all(|r| r.aspect == "functional"),
"rows={rows:?}"
);
}
}