X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Futil%2Ftest_utils.rs;h=0606e36e50e01d88496351e18dc7c019f94aae1e;hb=0ce0d483199c199979c3e831c14eaf3392183f1f;hp=2c34bc92c7e2eb5b38901cb7df06de73e0435d46;hpb=0cba31fd38615c8608960f87bdd9637b712904a1;p=rust-lightning diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index 2c34bc92c..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) { *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);