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 <noreply@anthropic.com>
This commit is contained in:
2026-11-07 05:55:39 +00:00
parent f6ba08d506
commit 46392c55e1

View File

@@ -114,9 +114,9 @@ url = "http://127.0.0.1:{feed_port}/feed.xml"
} }
/// A daemon, its log going to `log`. /// 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(); 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 { 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. /// 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(); let started = Instant::now();
assert!(Command::new("kill").args(["-TERM", &child.id().to_string()]).status().unwrap().success()); assert!(Command::new("kill").args(["-TERM", &child.id().to_string()]).status().unwrap().success());
loop { loop {