]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Improve debuggability when tests fail due to excess events 2022-09-always-probe-failed
authorMatt Corallo <git@bluematt.me>
Wed, 7 Sep 2022 21:53:13 +0000 (21:53 +0000)
committerMatt Corallo <git@bluematt.me>
Thu, 8 Sep 2022 18:54:20 +0000 (18:54 +0000)
lightning/src/ln/functional_test_utils.rs
lightning/src/util/test_utils.rs

index 11f61cad502066a0d71026cd4fc5c538acc4d00b..d8c1b75fad206cd1a144c06131bb9197c860fb9e 100644 (file)
@@ -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.
                        {
index b4d26904706240de647eec14ef97ef5b175ff8cf..7a32b13e60da6fbaef3c734d813d912fada9f440 100644 (file)
@@ -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<HashMap<(String, String), usize>>,
 }
 
@@ -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)| {