X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Futil%2Ftest_utils.rs;h=0606e36e50e01d88496351e18dc7c019f94aae1e;hb=0ce0d483199c199979c3e831c14eaf3392183f1f;hp=e5c63502354fba581c02691c6f4e92cd8ab5fff9;hpb=88ce7d6575dd376e98e680d0c0813c7b79151773;p=rust-lightning diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index e5c635023..0606e36e5 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -931,6 +931,7 @@ pub struct TestLogger { level: Level, pub(crate) id: String, pub lines: Mutex>, + pub context: Mutex, Option), usize>>, } impl TestLogger { @@ -941,7 +942,8 @@ impl TestLogger { TestLogger { level: Level::Trace, id, - lines: Mutex::new(HashMap::new()) + lines: Mutex::new(HashMap::new()), + context: Mutex::new(HashMap::new()), } } pub fn enable(&mut self, level: Level) { @@ -976,11 +978,23 @@ impl TestLogger { }).map(|(_, c) | { c }).sum(); assert_eq!(l, count) } + + pub fn assert_log_context_contains( + &self, module: &str, peer_id: Option, channel_id: Option, count: usize + ) { + let context_entries = self.context.lock().unwrap(); + let l: usize = context_entries.iter() + .filter(|&(&(ref m, ref p, ref c), _)| m == module && *p == peer_id && *c == channel_id) + .map(|(_, c) | c) + .sum(); + assert_eq!(l, count) + } } impl Logger for TestLogger { - fn log(&self, record: &Record) { + fn log(&self, record: Record) { *self.lines.lock().unwrap().entry((record.module_path.to_string(), format!("{}", record.args))).or_insert(0) += 1; + *self.context.lock().unwrap().entry((record.module_path.to_string(), record.peer_id, record.channel_id)).or_insert(0) += 1; if record.level >= self.level { #[cfg(all(not(ldk_bench), feature = "std"))] { let pfx = format!("{} {} [{}:{}]", self.id, record.level.to_string(), record.module_path, record.line);