From: Matt Corallo Date: Wed, 7 Sep 2022 21:53:13 +0000 (+0000) Subject: Improve debuggability when tests fail due to excess events X-Git-Tag: v0.0.111~11^2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=refs%2Fheads%2F2022-09-always-probe-failed;p=rust-lightning Improve debuggability when tests fail due to excess events --- diff --git a/lightning/src/ln/functional_test_utils.rs b/lightning/src/ln/functional_test_utils.rs index 11f61cad5..d8c1b75fa 100644 --- a/lightning/src/ln/functional_test_utils.rs +++ b/lightning/src/ln/functional_test_utils.rs @@ -304,9 +304,18 @@ impl<'a, 'b, 'c> Drop for Node<'a, 'b, 'c> { fn drop(&mut self) { if !panicking() { // Check that we processed all pending events - assert!(self.node.get_and_clear_pending_msg_events().is_empty()); - assert!(self.node.get_and_clear_pending_events().is_empty()); - assert!(self.chain_monitor.added_monitors.lock().unwrap().is_empty()); + let msg_events = self.node.get_and_clear_pending_msg_events(); + if !msg_events.is_empty() { + panic!("Had excess message events on node {}: {:?}", self.logger.id, msg_events); + } + let events = self.node.get_and_clear_pending_events(); + if !events.is_empty() { + panic!("Had excess events on node {}: {:?}", self.logger.id, events); + } + let added_monitors = self.chain_monitor.added_monitors.lock().unwrap().split_off(0); + if !added_monitors.is_empty() { + panic!("Had {} excess added monitors on node {}", added_monitors.len(), self.logger.id); + } // Check that if we serialize the Router, we can deserialize it again. { diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index b4d269047..7a32b13e6 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -517,10 +517,7 @@ impl events::MessageSendEventsProvider for TestRoutingMessageHandler { pub struct TestLogger { level: Level, - #[cfg(feature = "std")] - id: String, - #[cfg(not(feature = "std"))] - _id: String, + pub(crate) id: String, pub lines: Mutex>, } @@ -531,10 +528,7 @@ impl TestLogger { pub fn with_id(id: String) -> TestLogger { TestLogger { level: Level::Trace, - #[cfg(feature = "std")] id, - #[cfg(not(feature = "std"))] - _id: id, lines: Mutex::new(HashMap::new()) } } @@ -558,10 +552,10 @@ impl TestLogger { assert_eq!(l, count) } - /// Search for the number of occurrences of logged lines which - /// 1. belong to the specified module and - /// 2. match the given regex pattern. - /// Assert that the number of occurrences equals the given `count` + /// Search for the number of occurrences of logged lines which + /// 1. belong to the specified module and + /// 2. match the given regex pattern. + /// Assert that the number of occurrences equals the given `count` pub fn assert_log_regex(&self, module: String, pattern: regex::Regex, count: usize) { let log_entries = self.lines.lock().unwrap(); let l: usize = log_entries.iter().filter(|&(&(ref m, ref l), _c)| {