H: dedupe integration test block

This commit is contained in:
ari committed 2026-10-20 16:18:19 -04:00
1 parent 33a49533a3
commit 7252b0c966
1 file changed
+33 -36
+33 -36
View File
@@ -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",
);
}