From 7252b0c96691fed4c1c7482245199aec0788b26a Mon Sep 17 00:00:00 2001 From: ari Date: Tue, 20 Oct 2026 16:18:19 -0400 Subject: [PATCH] H: dedupe integration test block --- tests/integration.rs | 69 +++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 36 deletions(-) diff --git a/tests/integration.rs b/tests/integration.rs index 1325433..7be844e 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -403,6 +403,29 @@ fn sigterm_with_open_sse_client_exits_promptly() { assert!(started, "server did not stay up on any of three ports"); } +/// Signals the child and waits for a successful exit. Anything still running +/// after `bound` is killed and the test fails with `panic_msg`. +fn sigterm_and_wait(child: &mut std::process::Child, bound: Duration, panic_msg: &str) { + let pid = child.id().to_string(); + assert!(std::process::Command::new("kill") + .args(["-TERM", &pid]) + .status() + .unwrap() + .success()); + let start = std::time::Instant::now(); + loop { + if let Some(st) = child.try_wait().unwrap() { + assert!(st.success(), "exit status {st}"); + return; + } + if start.elapsed() > bound { + let _ = child.kill(); + panic!("{panic_msg}"); + } + std::thread::sleep(Duration::from_millis(50)); + } +} + /// One attempt on a fresh port. `false` means the child exited before it /// served, which only happens when the probed port was taken by someone else. fn sse_stream_then_sigterm() -> bool { @@ -456,24 +479,11 @@ fn sse_stream_then_sigterm_on(port: u16) -> bool { .unwrap(); let mut buf = [0u8; 512]; let _ = conn.read(&mut buf); - let pid = child.id().to_string(); - assert!(std::process::Command::new("kill") - .args(["-TERM", &pid]) - .status() - .unwrap() - .success()); - let start = std::time::Instant::now(); - loop { - if let Some(st) = child.try_wait().unwrap() { - assert!(st.success(), "exit status {st}"); - break; - } - if start.elapsed() > Duration::from_secs(10) { - let _ = child.kill(); - panic!("process did not exit within 10s of SIGTERM"); - } - std::thread::sleep(Duration::from_millis(50)); - } + sigterm_and_wait( + &mut child, + Duration::from_secs(10), + "process did not exit within 10s of SIGTERM", + ); true } @@ -579,22 +589,9 @@ fn sigterm_with_inflight_mcp_tail_exits_within_bound() { Some(&sid), false, ); - let pid = child.id().to_string(); - assert!(std::process::Command::new("kill") - .args(["-TERM", &pid]) - .status() - .unwrap() - .success()); - let start = std::time::Instant::now(); - loop { - if let Some(st) = child.try_wait().unwrap() { - assert!(st.success(), "exit status {st}"); - break; - } - if start.elapsed() > Duration::from_secs(25) { - let _ = child.kill(); - panic!("process did not exit within the shutdown bound"); - } - std::thread::sleep(Duration::from_millis(50)); - } + sigterm_and_wait( + &mut child, + Duration::from_secs(25), + "process did not exit within the shutdown bound", + ); }