From 4c0ead4a3e3726fb229d297c42fde856478b64a8 Mon Sep 17 00:00:00 2001 From: Anthony Eid <56899983+Anthony-Eid@users.noreply.github.com> Date: Wed, 30 Sep 2026 15:48:08 +0000 Subject: [PATCH] gpui: Fix flaky hang monitor shutdown test (#64993) `profiler::hang::tests::app_flushes_its_hang_monitor_on_shutdown` fails intermittently on CI ([example](https://github.com/zed-industries/zed/actions/runs/36730826643/job/109954752762)). `App::shutdown` requests a flush from the hang monitor and waits for it with `block_with_timeout`, which in tests runs on the deterministic `TestScheduler`. The monitor is a real OS thread (`HangDetection`), so the outcome depends on timing: - If the monitor finishes after shutdown starts waiting, its `done.send(())` wakes the scheduler from the `HangDetection` thread, and `end_test` panics with "Your test is not deterministic" (the CI failure). - If it hasn't finished when shutdown first checks, parking is forbidden, so the timed wait gives up immediately and the `Some(Flush)` assertion fails (reproduced locally). The test now calls `cx.executor().allow_parking()`, the existing opt-in for tests that involve real threads. Shutdown can then wait for the flush (still capped by `SHUTDOWN_TIMEOUT`), and the cross-thread wake is allowed. Production code is unchanged. Before the change, locally on macOS: `ITERATIONS=200` failed once, and 1 of 500 separate-process runs failed. After the change: all 200 iterations and 300 separate-process runs (as nextest does) passed. Release Notes: - [GPUI] Fixed a flaky hang monitor shutdown test --- crates/gpui/src/profiler/hang.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/gpui/src/profiler/hang.rs b/crates/gpui/src/profiler/hang.rs index e251f64176b..03c2f302990 100644 --- a/crates/gpui/src/profiler/hang.rs +++ b/crates/gpui/src/profiler/hang.rs @@ -691,6 +691,10 @@ mod tests { fn app_flushes_its_hang_monitor_on_shutdown(cx: &mut TestAppContext) { use super::{HangMonitorConfig, HangMonitorPollReason}; + // The monitor runs on a real OS thread, so shutdown has to park until it + // finishes the flush, and its completion wakes the scheduler from that thread. + cx.executor().allow_parking(); + let (sender, receiver) = std::sync::mpsc::channel(); cx.update(|cx| { cx.start_hang_monitor(