From 46392c55e1872843659580e682353740c31d91e2 Mon Sep 17 00:00:00 2001 From: rays Date: Sat, 7 Nov 2026 05:55:39 +0000 Subject: [PATCH] The daemon test stops its daemons when an assertion fails (#400) A failed assertion skipped the terminate at the end, and the two runs that failed while the test was written left their daemons running for an hour on their scratch sockets and ports. Each daemon the test starts is now killed when it is dropped, however the test ends. Co-Authored-By: Claude Opus 5.5 --- crates/ipx/tests/daemon.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/crates/ipx/tests/daemon.rs b/crates/ipx/tests/daemon.rs index 1cc5f8e..61c2114 100644 --- a/crates/ipx/tests/daemon.rs +++ b/crates/ipx/tests/daemon.rs @@ -114,9 +114,9 @@ url = "http://127.0.0.1:{feed_port}/feed.xml" } /// A daemon, its log going to `log`. - fn daemon(&self, log: &str) -> Child { + fn daemon(&self, log: &str) -> Daemon { let log = std::fs::File::create(self.root.join(log)).unwrap(); - self.ipx(&["daemon"]).stdout(Stdio::null()).stderr(log).spawn().unwrap() + Daemon(self.ipx(&["daemon"]).stdout(Stdio::null()).stderr(log).spawn().unwrap()) } fn log(&self, name: &str) -> String { @@ -147,7 +147,18 @@ fn text(o: &Output) -> String { } /// SIGTERM, as `docker stop` sends; how long it took to exit. -fn terminate(child: &mut Child) -> Duration { +/// A daemon this test started, killed when dropped: a failed assertion left two running for an +/// hour, holding their scratch sockets and ports. +struct Daemon(Child); + +impl Drop for Daemon { + fn drop(&mut self) { + let _ = self.0.kill(); + let _ = self.0.wait(); + } +} + +fn terminate(Daemon(child): &mut Daemon) -> Duration { let started = Instant::now(); assert!(Command::new("kill").args(["-TERM", &child.id().to_string()]).status().unwrap().success()); loop {