Skip node2.is_running() on Windows

`node2.is_running()` can return `true` on Windows, even though `node2`
has logged a panic. This cleanup code only runs if `node2` fails to panic
and exit as expected. So it's ok for us to skip it.

See #1781 for details.
This commit is contained in:
teor 2021-02-19 16:02:48 +10:00
parent 631fe22422
commit c51fd688ee
2 changed files with 21 additions and 3 deletions

View File

@ -160,6 +160,11 @@ pub struct TestChild<T> {
impl<T> TestChild<T> {
/// Kill the child process.
///
/// ## BUGS
///
/// On Windows, this function can return `Ok` for processes that have
/// panicked. See #1781.
#[spandoc::spandoc]
pub fn kill(&mut self) -> Result<()> {
/// SPANDOC: Killing child process
@ -355,6 +360,11 @@ impl<T> TestChild<T> {
}
/// Is this process currently running?
///
/// ## BUGS
///
/// On Windows, this function can return `true` for processes that have
/// panicked. See #1781.
pub fn is_running(&mut self) -> bool {
matches!(self.child.try_wait(), Ok(None))
}

View File

@ -1229,14 +1229,22 @@ where
// In node1 we want to check for the success regex
// If there are any errors, we also want to print the node2 output.
let output1 = node1.wait_with_output();
// This mut is only used on cfg(unix), due to #1781.
#[allow(unused_mut)]
let (output1, mut node2) = node2.kill_on_error(output1)?;
// node2 should have panicked due to a conflict. Kill it here
// anyway, so it doesn't outlive the test on error.
// node2 should have panicked due to a conflict. Kill it here anyway, so it
// doesn't outlive the test on error.
//
// This code doesn't work on Windows. It's cleanup code that only runs when
// node2 doesn't panic as expected. So it's ok to skip it. See #1781.
#[cfg(unix)]
if node2.is_running() {
use color_eyre::eyre::eyre;
return node2
.kill_on_error::<(), _>(Err(eyre!("conflicted node2 did not panic")))
.kill_on_error::<(), _>(Err(eyre!(
"conflicted node2 was still running, but the test expected a panic"
)))
.context_from(&output1)
.map(|_| ());
}