From b02b4754c027bd751825c8e3b96766a5898187b1 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Mon, 4 Mar 2024 10:54:38 +0000 Subject: test: ensure failed tests timeout resolve a long standing test issue where failures to output the correct message in the cli would result in the test never ending rather than failing the many test cases updated in this change are to ensure failures are caught rather than ignored some of them are just refactored to remove calling an extra function, which is no longer needed note: this doesn't fix the intermittent issue, most commonly experienced under the nix configuration, where tests that should pass occationally never end preventing the rest of the suite from running --- test_utils/src/lib.rs | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) (limited to 'test_utils') diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs index 8a65d39..712753e 100644 --- a/test_utils/src/lib.rs +++ b/test_utils/src/lib.rs @@ -646,6 +646,22 @@ impl CliTester { } } + fn exp_string(&mut self, message: &str) -> Result { + match self + .rexpect_session + .exp_string(message) + .context("expected immediate end but got timed out") + { + Ok(before) => Ok(before), + Err(e) => { + for p in [51, 52, 53, 55, 56, 57] { + let _ = relay::shutdown_relay(8000 + p); + } + Err(e) + } + } + } + /// returns what came before expected message pub fn expect_eventually(&mut self, message: S) -> Result where @@ -653,10 +669,7 @@ impl CliTester { { let message_string = message.into(); let message = message_string.as_str(); - let before = self - .rexpect_session - .exp_string(message) - .context("exp_string failed")?; + let before = self.exp_string(message).context("exp_string failed")?; Ok(before) } @@ -692,9 +705,24 @@ impl CliTester { Ok(self) } + fn exp_eof(&mut self) -> Result { + match self + .rexpect_session + .exp_eof() + .context("expected immediate end but got timed out") + { + Ok(before) => Ok(before), + Err(e) => { + for p in [51, 52, 53, 55, 56, 57] { + let _ = relay::shutdown_relay(8000 + p); + } + Err(e) + } + } + } + pub fn expect_end(&mut self) -> Result<()> { let before = self - .rexpect_session .exp_eof() .context("expected immediate end but got timed out")?; ensure!( @@ -709,7 +737,6 @@ impl CliTester { pub fn expect_end_with(&mut self, message: &str) -> Result<()> { let before = self - .rexpect_session .exp_eof() .context("expected immediate end but got timed out")?; assert_eq!(before, message); @@ -718,7 +745,6 @@ impl CliTester { pub fn expect_end_eventually_and_print(&mut self) -> Result<()> { let before = self - .rexpect_session .exp_eof() .context("expected immediate end but got timed out")?; println!("ended eventually with:"); @@ -728,7 +754,6 @@ impl CliTester { pub fn expect_end_with_whitespace(&mut self) -> Result<()> { let before = self - .rexpect_session .exp_eof() .context("expected immediate end but got timed out")?; assert_eq!(before.trim(), ""); @@ -736,8 +761,7 @@ impl CliTester { } pub fn expect_end_eventually(&mut self) -> Result { - self.rexpect_session - .exp_eof() + self.exp_eof() .context("expected end eventually but got timed out") } -- cgit v1.2.3