Skip to content

Commit b4c7bc4

Browse files
fix(sandbox): stabilize forked socket owner test (#1417)
Increase the polling deadline from 2s to 5s to tolerate loaded CI machines, and add a ChildGuard drop guard so the forked child is always reaped even if the test panics. Signed-off-by: Derek Carr <decarr@redhat.com>
1 parent 71209e6 commit b4c7bc4

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,17 @@ mod tests {
762762
use std::net::{TcpListener, TcpStream};
763763
use std::time::{Duration, Instant};
764764

765+
struct ChildGuard(libc::pid_t);
766+
impl Drop for ChildGuard {
767+
fn drop(&mut self) {
768+
#[allow(unsafe_code)]
769+
unsafe {
770+
libc::kill(self.0, libc::SIGKILL);
771+
libc::waitpid(self.0, std::ptr::null_mut(), 0);
772+
}
773+
}
774+
}
775+
765776
let listener = TcpListener::bind("127.0.0.1:0").expect("bind listener");
766777
let listener_port = listener.local_addr().unwrap().port();
767778
let stream = TcpStream::connect(("127.0.0.1", listener_port)).expect("connect");
@@ -781,9 +792,10 @@ mod tests {
781792
}
782793
}
783794

795+
let _guard = ChildGuard(child_pid);
784796
let child_pid_u32 = child_pid.cast_unsigned();
785797
let entrypoint_pid = std::process::id();
786-
let deadline = Instant::now() + Duration::from_secs(2);
798+
let deadline = Instant::now() + Duration::from_secs(5);
787799
let owners = loop {
788800
let owners = resolve_tcp_peer_socket_owners(entrypoint_pid, peer_port)
789801
.expect("resolve socket owners");
@@ -802,13 +814,6 @@ mod tests {
802814
std::thread::sleep(Duration::from_millis(20));
803815
};
804816

805-
// libc/syscall FFI requires unsafe
806-
#[allow(unsafe_code)]
807-
unsafe {
808-
libc::kill(child_pid, libc::SIGKILL);
809-
libc::waitpid(child_pid, std::ptr::null_mut(), 0);
810-
}
811-
812817
let owner_pids = owners
813818
.owners
814819
.iter()

0 commit comments

Comments
 (0)