Skip to content

Commit dd591c2

Browse files
committed
Improve debuggability when tests fail due to excess events
1 parent c1607bc commit dd591c2

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

lightning/src/ln/functional_test_utils.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,18 @@ impl<'a, 'b, 'c> Drop for Node<'a, 'b, 'c> {
304304
fn drop(&mut self) {
305305
if !panicking() {
306306
// Check that we processed all pending events
307-
assert!(self.node.get_and_clear_pending_msg_events().is_empty());
308-
assert!(self.node.get_and_clear_pending_events().is_empty());
309-
assert!(self.chain_monitor.added_monitors.lock().unwrap().is_empty());
307+
let msg_events = self.node.get_and_clear_pending_msg_events();
308+
if !msg_events.is_empty() {
309+
panic!("Had excess message events on node {}: {:?}", self.logger.id, msg_events);
310+
}
311+
let events = self.node.get_and_clear_pending_events();
312+
if !events.is_empty() {
313+
panic!("Had excess events on node {}: {:?}", self.logger.id, events);
314+
}
315+
let added_monitors = self.chain_monitor.added_monitors.lock().unwrap().split_off(0);
316+
if !added_monitors.is_empty() {
317+
panic!("Had {} excess added monitors on node {}", added_monitors.len(), self.logger.id);
318+
}
310319

311320
// Check that if we serialize the Router, we can deserialize it again.
312321
{

lightning/src/util/test_utils.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -517,10 +517,7 @@ impl events::MessageSendEventsProvider for TestRoutingMessageHandler {
517517

518518
pub struct TestLogger {
519519
level: Level,
520-
#[cfg(feature = "std")]
521-
id: String,
522-
#[cfg(not(feature = "std"))]
523-
_id: String,
520+
pub(crate) id: String,
524521
pub lines: Mutex<HashMap<(String, String), usize>>,
525522
}
526523

@@ -531,10 +528,7 @@ impl TestLogger {
531528
pub fn with_id(id: String) -> TestLogger {
532529
TestLogger {
533530
level: Level::Trace,
534-
#[cfg(feature = "std")]
535531
id,
536-
#[cfg(not(feature = "std"))]
537-
_id: id,
538532
lines: Mutex::new(HashMap::new())
539533
}
540534
}
@@ -558,10 +552,10 @@ impl TestLogger {
558552
assert_eq!(l, count)
559553
}
560554

561-
/// Search for the number of occurrences of logged lines which
562-
/// 1. belong to the specified module and
563-
/// 2. match the given regex pattern.
564-
/// Assert that the number of occurrences equals the given `count`
555+
/// Search for the number of occurrences of logged lines which
556+
/// 1. belong to the specified module and
557+
/// 2. match the given regex pattern.
558+
/// Assert that the number of occurrences equals the given `count`
565559
pub fn assert_log_regex(&self, module: String, pattern: regex::Regex, count: usize) {
566560
let log_entries = self.lines.lock().unwrap();
567561
let l: usize = log_entries.iter().filter(|&(&(ref m, ref l), _c)| {

0 commit comments

Comments
 (0)