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 {