This repository has been archived on 2026-10-10. You can view files and clone it, but cannot push or open issues or pull requests.
molotov/crates/molotov-bootstrap/tests/watchdog_test.rs

43 lines
1.5 KiB
Rust

// SPDX-License-Identifier: GPL-3.0-or-later
use molotov_bootstrap::watchdog::{LaunchStatus, LaunchWatchdog};
use tempfile::tempdir;
#[test]
fn test_safe_mode_activates_after_two_crashes() {
let temp = tempdir().unwrap();
let state_file = temp.path().join("launch_state.json");
let mut watchdog = LaunchWatchdog::new(state_file.clone());
// Crash 1
watchdog.record_start().unwrap();
watchdog.record_crash().unwrap();
assert_eq!(watchdog.status(), LaunchStatus::Healthy);
// Crash 2
watchdog.record_start().unwrap();
watchdog.record_crash().unwrap();
assert_eq!(watchdog.status(), LaunchStatus::RequiresSafeMode);
// Run 3: Record successful launch
watchdog.record_success().unwrap();
assert_eq!(watchdog.status(), LaunchStatus::Healthy);
}
#[test]
fn test_safe_mode_activates_on_interrupted_launches() {
let temp = tempdir().unwrap();
let state_file = temp.path().join("launch_state_interrupted.json");
let mut watchdog = LaunchWatchdog::new(state_file);
// Launch 1 starts and dies (in_flight stays true)
watchdog.record_start().unwrap();
assert_eq!(watchdog.status(), LaunchStatus::Healthy);
// Launch 2 starts (detects launch 1 died in flight) and dies
watchdog.record_start().unwrap();
assert_eq!(watchdog.status(), LaunchStatus::Healthy);
// Launch 3 starts (detects launch 2 died in flight -> 2 failures reached)
watchdog.record_start().unwrap();
assert_eq!(watchdog.status(), LaunchStatus::RequiresSafeMode);
}