pub node_seed: [u8; 32],
pub network_payment_count: Rc<RefCell<u8>>,
pub network_chan_count: Rc<RefCell<u32>>,
+ pub logger: Arc<test_utils::TestLogger>
}
impl Drop for Node {
fn drop(&mut self) {
let payment_count = Rc::new(RefCell::new(0));
for i in 0..node_count {
- let logger: Arc<Logger> = Arc::new(test_utils::TestLogger::with_id(format!("node {}", i)));
+ let test_logger = Arc::new(test_utils::TestLogger::with_id(format!("node {}", i)));
+ let logger = &(Arc::clone(&test_logger) as Arc<Logger>);
let feeest = Arc::new(test_utils::TestFeeEstimator { sat_per_kw: 253 });
let chain_monitor = Arc::new(chaininterface::ChainWatchInterfaceUtil::new(Network::Testnet, Arc::clone(&logger)));
let block_notifier = Arc::new(chaininterface::BlockNotifier::new(chain_monitor.clone()));
network_payment_count: payment_count.clone(),
network_chan_count: chan_count.clone(),
block_notifier,
+ logger: test_logger
});
}
use std::time::{SystemTime, UNIX_EPOCH};
use std::sync::{Arc,Mutex};
use std::{mem};
+use std::collections::HashMap;
pub struct TestVecWriter(pub Vec<u8>);
impl Writer for TestVecWriter {
pub struct TestLogger {
level: Level,
id: String,
+ pub lines: Mutex<HashMap<(String, String), usize>>,
}
impl TestLogger {
TestLogger {
level: Level::Trace,
id,
+ lines: Mutex::new(HashMap::new())
}
}
pub fn enable(&mut self, level: Level) {
self.level = level;
}
+ pub fn assert_log(&self, module: String, line: String, count: usize) {
+ let log_entries = self.lines.lock().unwrap();
+ assert_eq!(log_entries.get(&(module, line)), Some(&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;
if self.level >= record.level {
println!("{:<5} {} [{} : {}, {}] {}", record.level.to_string(), self.id, record.module_path, record.file, record.line, record.args);
}