#[cfg(all(feature = "metrics", feature = "pool", not(loom)))]
use metrics::counter;
pub const POOL_SCHEDULER_FAILURES: &str = "wireframe_pool_scheduler_failures_total";
#[cfg(all(feature = "metrics", feature = "pool", not(loom)))]
pub(crate) fn inc_pool_scheduler_failure() { counter!(POOL_SCHEDULER_FAILURES).increment(1); }
#[cfg(all(not(feature = "metrics"), feature = "pool", not(loom)))]
pub(crate) fn inc_pool_scheduler_failure() {}
#[cfg(all(test, feature = "metrics", feature = "pool", not(loom)))]
mod tests {
use metrics_util::debugging::{DebugValue, DebuggingRecorder};
use super::{POOL_SCHEDULER_FAILURES, inc_pool_scheduler_failure};
#[test]
fn scheduler_failure_is_recorded_without_a_pool_label() {
let recorder = DebuggingRecorder::new();
let snapshotter = recorder.snapshotter();
::metrics::with_local_recorder(&recorder, inc_pool_scheduler_failure);
let entries = snapshotter.snapshot().into_vec();
let failure = entries.iter().find_map(|(key, _, _, value)| {
(key.key().name() == POOL_SCHEDULER_FAILURES).then_some((key, value))
});
let Some((key, value)) = failure else {
panic!("the scheduler failure counter was not recorded");
};
assert!(
key.key().labels().next().is_none(),
"the failure counter must not carry an unbounded pool label"
);
assert!(
matches!(value, DebugValue::Counter(count) if *count == 1),
"the failure counter must increment once per failure"
);
}
}