Skip to content

Commit f339b5b

Browse files
committed
test(sandbox): bound the whole SIGTERM exit test
Run the child through run_isolated so a stall during setup fails the test instead of hanging it, and have the fake supervisor send SIGTERM once its exchanges are parked. Signed-off-by: divesh <[email protected]>
1 parent 0037efe commit f339b5b

1 file changed

Lines changed: 20 additions & 47 deletions

File tree

‎crates/openshell-sandbox/src/boundary_server.rs‎

Lines changed: 20 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6237,55 +6237,12 @@ mod linux {
62376237
#[test]
62386238
fn sigterm_exits_while_the_supervisor_holds_an_exchange_open() {
62396239
const CHILD_MARKER: &str = "OPENSHELL_TEST_BOUNDARY_SIGTERM_CHILD";
6240-
const READY: &str = "boundary-sigterm-test-ready";
62416240
const EXIT_BUDGET: Duration = Duration::from_secs(10);
62426241
if std::env::var_os(CHILD_MARKER).is_none() {
6243-
use std::io::BufRead as _;
6244-
let mut child = std::process::Command::new(
6245-
std::env::current_exe().expect("current test executable"),
6246-
)
6247-
.args([
6248-
"--exact",
6242+
run_isolated(
62496243
"boundary_server::linux::tests::sigterm_exits_while_the_supervisor_holds_an_exchange_open",
6250-
"--nocapture",
6251-
])
6252-
.env(CHILD_MARKER, "1")
6253-
.stdout(std::process::Stdio::piped())
6254-
.spawn()
6255-
.expect("run isolated termination test");
6256-
let mut lines =
6257-
io::BufReader::new(child.stdout.take().expect("child stdout")).lines();
6258-
assert!(
6259-
lines.any(|line| line.is_ok_and(|line| line == READY)),
6260-
"the boundary never parked an exchange"
6261-
);
6262-
std::thread::spawn(move || lines.for_each(drop));
6263-
nix::sys::signal::kill(
6264-
nix::unistd::Pid::from_raw(i32::try_from(child.id()).expect("child PID")),
6265-
nix::sys::signal::Signal::SIGTERM,
6266-
)
6267-
.expect("send SIGTERM");
6268-
let signalled = std::time::Instant::now();
6269-
let status = loop {
6270-
if let Some(status) = child.try_wait().expect("poll boundary") {
6271-
break Some(status);
6272-
}
6273-
if signalled.elapsed() > EXIT_BUDGET {
6274-
break None;
6275-
}
6276-
std::thread::sleep(Duration::from_millis(20));
6277-
};
6278-
let elapsed = signalled.elapsed();
6279-
if status.is_none() {
6280-
let _ = child.kill();
6281-
let _ = child.wait();
6282-
}
6283-
let status = status.unwrap_or_else(|| {
6284-
panic!("the boundary was still running {elapsed:?} after SIGTERM")
6285-
});
6286-
assert!(
6287-
status.success(),
6288-
"isolated termination test failed: {status}"
6244+
CHILD_MARKER,
6245+
Duration::from_mins(1),
62896246
);
62906247
return;
62916248
}
@@ -6341,6 +6298,7 @@ mod linux {
63416298
)
63426299
};
63436300
let opening = test_open_request(&boundary.config);
6301+
let (signalled_sender, signalled) = std::sync::mpsc::channel();
63446302
std::thread::spawn(move || {
63456303
let supervisor = std::panic::AssertUnwindSafe(|| {
63466304
supervisor_runtime.block_on(async move {
@@ -6444,7 +6402,14 @@ mod linux {
64446402
"a parked exchange answered before termination"
64456403
);
64466404
}
6447-
println!("{READY}");
6405+
signalled_sender
6406+
.send(std::time::Instant::now())
6407+
.expect("report SIGTERM time");
6408+
nix::sys::signal::kill(
6409+
nix::unistd::Pid::this(),
6410+
nix::sys::signal::Signal::SIGTERM,
6411+
)
6412+
.expect("send SIGTERM");
64486413
std::future::pending::<()>().await;
64496414
drop(parked);
64506415
});
@@ -6465,6 +6430,14 @@ mod linux {
64656430
install_boundary_signal_handlers().expect("install termination handlers");
64666431
serve_then_stop(process_runtime, &listener, boundary)
64676432
.expect("terminate after supervisor confirmation");
6433+
let elapsed = signalled
6434+
.recv()
6435+
.expect("the supervisor sent SIGTERM")
6436+
.elapsed();
6437+
assert!(
6438+
elapsed < EXIT_BUDGET,
6439+
"the boundary took {elapsed:?} to stop after SIGTERM"
6440+
);
64686441
}
64696442

64706443
#[tokio::test(flavor = "multi_thread")]

0 commit comments

Comments
 (0)