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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user