From 2af9d2d4c7a3ebace181d0ed63c1993e186446ae Mon Sep 17 00:00:00 2001 From: CodeGraph Test Date: Sat, 3 Oct 2026 11:06:58 +0800 Subject: [PATCH] test(cli): stop the viewer when a test fails A failing assertion in a cli_ui test unwound past `Viewer::stop`, and `std::process::Child` neither kills nor waits when it is dropped, so the `codegraph ui` server the test started outlived the test binary. Three such servers had been running for twelve hours. `Viewer` now kills and reaps its child in `Drop`, which both `stop` and the panic in `start` go through. --- crates/codegraph-cli/tests/cli_ui.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/crates/codegraph-cli/tests/cli_ui.rs b/crates/codegraph-cli/tests/cli_ui.rs index 47d6eee..17c66e2 100644 --- a/crates/codegraph-cli/tests/cli_ui.rs +++ b/crates/codegraph-cli/tests/cli_ui.rs @@ -123,10 +123,7 @@ impl Viewer { break; } } - Err(_) => { - let _ = viewer.child.kill(); - panic!("codegraph ui never printed a URL:\n{}", viewer.output); - } + Err(_) => panic!("codegraph ui never printed a URL:\n{}", viewer.output), } } viewer @@ -148,7 +145,16 @@ impl Viewer { true } - fn stop(mut self) { + fn stop(self) { + drop(self); + } +} + +/// A failing assertion unwinds through here too. `Child` neither kills nor +/// waits when dropped, so without this a test that fails while its server +/// runs leaves that server running after the test binary exits. +impl Drop for Viewer { + fn drop(&mut self) { let _ = self.child.kill(); let _ = self.child.wait(); }