diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-03-04 10:54:38 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-03-04 10:54:38 +0000 |
| commit | b02b4754c027bd751825c8e3b96766a5898187b1 (patch) | |
| tree | 5d82b0a1f3094eb5cc7968d4607fd51d713f3bba /test_utils | |
| parent | 6e48a90620cc083ab3617a6583123de9e721b181 (diff) | |
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
Diffstat (limited to 'test_utils')
| -rw-r--r-- | test_utils/src/lib.rs | 44 |
1 files changed, 34 insertions, 10 deletions
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 { | |||
| 646 | } | 646 | } |
| 647 | } | 647 | } |
| 648 | 648 | ||
| 649 | fn exp_string(&mut self, message: &str) -> Result<String> { | ||
| 650 | match self | ||
| 651 | .rexpect_session | ||
| 652 | .exp_string(message) | ||
| 653 | .context("expected immediate end but got timed out") | ||
| 654 | { | ||
| 655 | Ok(before) => Ok(before), | ||
| 656 | Err(e) => { | ||
| 657 | for p in [51, 52, 53, 55, 56, 57] { | ||
| 658 | let _ = relay::shutdown_relay(8000 + p); | ||
| 659 | } | ||
| 660 | Err(e) | ||
| 661 | } | ||
| 662 | } | ||
| 663 | } | ||
| 664 | |||
| 649 | /// returns what came before expected message | 665 | /// returns what came before expected message |
| 650 | pub fn expect_eventually<S>(&mut self, message: S) -> Result<String> | 666 | pub fn expect_eventually<S>(&mut self, message: S) -> Result<String> |
| 651 | where | 667 | where |
| @@ -653,10 +669,7 @@ impl CliTester { | |||
| 653 | { | 669 | { |
| 654 | let message_string = message.into(); | 670 | let message_string = message.into(); |
| 655 | let message = message_string.as_str(); | 671 | let message = message_string.as_str(); |
| 656 | let before = self | 672 | let before = self.exp_string(message).context("exp_string failed")?; |
| 657 | .rexpect_session | ||
| 658 | .exp_string(message) | ||
| 659 | .context("exp_string failed")?; | ||
| 660 | Ok(before) | 673 | Ok(before) |
| 661 | } | 674 | } |
| 662 | 675 | ||
| @@ -692,9 +705,24 @@ impl CliTester { | |||
| 692 | Ok(self) | 705 | Ok(self) |
| 693 | } | 706 | } |
| 694 | 707 | ||
| 708 | fn exp_eof(&mut self) -> Result<String> { | ||
| 709 | match self | ||
| 710 | .rexpect_session | ||
| 711 | .exp_eof() | ||
| 712 | .context("expected immediate end but got timed out") | ||
| 713 | { | ||
| 714 | Ok(before) => Ok(before), | ||
| 715 | Err(e) => { | ||
| 716 | for p in [51, 52, 53, 55, 56, 57] { | ||
| 717 | let _ = relay::shutdown_relay(8000 + p); | ||
| 718 | } | ||
| 719 | Err(e) | ||
| 720 | } | ||
| 721 | } | ||
| 722 | } | ||
| 723 | |||
| 695 | pub fn expect_end(&mut self) -> Result<()> { | 724 | pub fn expect_end(&mut self) -> Result<()> { |
| 696 | let before = self | 725 | let before = self |
| 697 | .rexpect_session | ||
| 698 | .exp_eof() | 726 | .exp_eof() |
| 699 | .context("expected immediate end but got timed out")?; | 727 | .context("expected immediate end but got timed out")?; |
| 700 | ensure!( | 728 | ensure!( |
| @@ -709,7 +737,6 @@ impl CliTester { | |||
| 709 | 737 | ||
| 710 | pub fn expect_end_with(&mut self, message: &str) -> Result<()> { | 738 | pub fn expect_end_with(&mut self, message: &str) -> Result<()> { |
| 711 | let before = self | 739 | let before = self |
| 712 | .rexpect_session | ||
| 713 | .exp_eof() | 740 | .exp_eof() |
| 714 | .context("expected immediate end but got timed out")?; | 741 | .context("expected immediate end but got timed out")?; |
| 715 | assert_eq!(before, message); | 742 | assert_eq!(before, message); |
| @@ -718,7 +745,6 @@ impl CliTester { | |||
| 718 | 745 | ||
| 719 | pub fn expect_end_eventually_and_print(&mut self) -> Result<()> { | 746 | pub fn expect_end_eventually_and_print(&mut self) -> Result<()> { |
| 720 | let before = self | 747 | let before = self |
| 721 | .rexpect_session | ||
| 722 | .exp_eof() | 748 | .exp_eof() |
| 723 | .context("expected immediate end but got timed out")?; | 749 | .context("expected immediate end but got timed out")?; |
| 724 | println!("ended eventually with:"); | 750 | println!("ended eventually with:"); |
| @@ -728,7 +754,6 @@ impl CliTester { | |||
| 728 | 754 | ||
| 729 | pub fn expect_end_with_whitespace(&mut self) -> Result<()> { | 755 | pub fn expect_end_with_whitespace(&mut self) -> Result<()> { |
| 730 | let before = self | 756 | let before = self |
| 731 | .rexpect_session | ||
| 732 | .exp_eof() | 757 | .exp_eof() |
| 733 | .context("expected immediate end but got timed out")?; | 758 | .context("expected immediate end but got timed out")?; |
| 734 | assert_eq!(before.trim(), ""); | 759 | assert_eq!(before.trim(), ""); |
| @@ -736,8 +761,7 @@ impl CliTester { | |||
| 736 | } | 761 | } |
| 737 | 762 | ||
| 738 | pub fn expect_end_eventually(&mut self) -> Result<String> { | 763 | pub fn expect_end_eventually(&mut self) -> Result<String> { |
| 739 | self.rexpect_session | 764 | self.exp_eof() |
| 740 | .exp_eof() | ||
| 741 | .context("expected end eventually but got timed out") | 765 | .context("expected end eventually but got timed out") |
| 742 | } | 766 | } |
| 743 | 767 | ||