diff --git a/msim/src/sim/runtime/mod.rs b/msim/src/sim/runtime/mod.rs index 1634923..67a5834 100644 --- a/msim/src/sim/runtime/mod.rs +++ b/msim/src/sim/runtime/mod.rs @@ -625,6 +625,33 @@ mod tests { use super::start_watchdog_with; use crate::{runtime::Runtime, time}; + #[test] + fn test_nested_watchdog_suppression() { + let runtime = Runtime::new(); + let handle = runtime.handle(); + + assert!(!handle.is_watchdog_suppressed()); + + let outer_guard = handle.suppress_watchdog(); + assert!(handle.is_watchdog_suppressed()); + + { + let inner_guard = handle.suppress_watchdog(); + assert!(handle.is_watchdog_suppressed()); + + drop(inner_guard); + + // Dropping the inner guard must not re-enable the watchdog + // while the outer guard is still active. + assert!(handle.is_watchdog_suppressed()); + } + + drop(outer_guard); + + // The watchdog should resume only after all guards are dropped. + assert!(!handle.is_watchdog_suppressed()); + } + #[test] fn test_watchdog() { // This test will panic if logging is enabled since the logging happens outside of a