Skip to content

Commit 6296f44

Browse files
committed
tests: fix monitor stop/resume tests to match exec loop
The tests called check_pause() once and expected it to block indefinitely. But check_pause() returns immediately when state is Running — only the real exec loop calls it in a loop. Fix by simulating the exec loop polling pattern: while !check_pause() { sleep(1ms); } Use request_quit() to cleanly break the loop after the stop/resume cycle is verified. Removes #[ignore] — both tests now pass reliably. Signed-off-by: Chao Liu <chao.liu.zevorn@gmail.com>
1 parent 0ecc0df commit 6296f44

1 file changed

Lines changed: 27 additions & 11 deletions

File tree

tests/src/monitor.rs

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,46 +22,62 @@ fn test_monitor_state_initial() {
2222
}
2323

2424
#[test]
25-
#[ignore = "deadlocks after MOM refactor — needs MonitorState rework"]
2625
fn test_monitor_state_stop_resume() {
2726
let ms = Arc::new(MonitorState::new());
2827
let ms2 = Arc::clone(&ms);
2928

30-
// Spawn a thread that parks when pause requested.
29+
// Simulate exec loop: keep calling check_pause()
30+
// until quit is requested.
3131
let handle = std::thread::spawn(move || {
32-
ms2.check_pause(); // blocks if PauseRequested
32+
while !ms2.check_pause() {
33+
std::thread::sleep(
34+
std::time::Duration::from_millis(1),
35+
);
36+
}
3337
});
3438

35-
// Give the spawned thread time to enter check_pause.
36-
std::thread::sleep(std::time::Duration::from_millis(50));
39+
// Give the exec-loop thread time to start polling.
40+
std::thread::sleep(
41+
std::time::Duration::from_millis(20),
42+
);
3743

38-
// Request stop — should block until parked.
44+
// Stop: blocks until the thread parks.
3945
ms.request_stop();
4046
assert_eq!(ms.vm_state(), VmState::Paused);
4147

42-
// Resume.
48+
// Resume: thread continues polling.
4349
ms.request_cont();
44-
handle.join().unwrap();
4550
assert_eq!(ms.vm_state(), VmState::Running);
51+
52+
// Quit to break the exec-loop thread.
53+
ms.request_quit();
54+
handle.join().unwrap();
4655
}
4756

4857
#[test]
49-
#[ignore = "deadlocks after MOM refactor — needs MonitorState rework"]
5058
fn test_monitor_state_stop_idempotent() {
5159
let ms = Arc::new(MonitorState::new());
5260
let ms2 = Arc::clone(&ms);
5361

5462
let handle = std::thread::spawn(move || {
55-
ms2.check_pause();
63+
while !ms2.check_pause() {
64+
std::thread::sleep(
65+
std::time::Duration::from_millis(1),
66+
);
67+
}
5668
});
5769

58-
std::thread::sleep(std::time::Duration::from_millis(50));
70+
std::thread::sleep(
71+
std::time::Duration::from_millis(20),
72+
);
73+
5974
ms.request_stop();
6075
// Second stop when already paused is idempotent.
6176
ms.request_stop();
6277
assert_eq!(ms.vm_state(), VmState::Paused);
6378

6479
ms.request_cont();
80+
ms.request_quit();
6581
handle.join().unwrap();
6682
}
6783

0 commit comments

Comments
 (0)