From 3287be5613b52567c113211e874fe53f8c642481 Mon Sep 17 00:00:00 2001 From: teor Date: Fri, 18 Mar 2022 08:54:10 +1000 Subject: [PATCH] Fix a potential hang in test child error reports --- zebra-test/src/command.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/zebra-test/src/command.rs b/zebra-test/src/command.rs index dcf208ad063..68174ebb589 100644 --- a/zebra-test/src/command.rs +++ b/zebra-test/src/command.rs @@ -741,6 +741,7 @@ impl ContextFrom<&TestStatus> for Report { impl ContextFrom<&mut TestChild> for Report { type Return = Report; + #[allow(clippy::print_stdout)] fn context_from(mut self, source: &mut TestChild) -> Self::Return { self = self.section(source.cmd.clone().header("Command:")); @@ -748,6 +749,12 @@ impl ContextFrom<&mut TestChild> for Report { self = self.context_from(&status); } + // Reading test child process output could hang if the child process is still running, + // so kill it first. + if let Some(child) = source.child.as_mut() { + let _ = child.kill(); + } + let mut stdout_buf = String::new(); let mut stderr_buf = String::new();