Skip to content

Commit 5feb2c2

Browse files
committed
Use common Persister for ChanManager error test
1 parent cb09783 commit 5feb2c2

File tree

1 file changed

+12
-24
lines changed
  • lightning-background-processor/src

1 file changed

+12
-24
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -414,17 +414,22 @@ mod tests {
414414

415415
struct Persister {
416416
data_dir: String,
417-
graph_error: Option<(std::io::ErrorKind, &'static str)>
417+
graph_error: Option<(std::io::ErrorKind, &'static str)>,
418+
manager_error: Option<(std::io::ErrorKind, &'static str)>
418419
}
419420

420421
impl Persister {
421422
fn new(data_dir: String) -> Self {
422-
Self { data_dir, graph_error: None }
423+
Self { data_dir, graph_error: None, manager_error: None }
423424
}
424425

425426
fn with_graph_error(self, error: std::io::ErrorKind, message: &'static str) -> Self {
426427
Self { graph_error: Some((error, message)), ..self }
427428
}
429+
430+
fn with_manager_error(self, error: std::io::ErrorKind, message: &'static str) -> Self {
431+
Self { manager_error: Some((error, message)), ..self }
432+
}
428433
}
429434

430435
impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L:Deref> super::Persister<Signer, M, T, K, F, L> for Persister where
@@ -435,7 +440,10 @@ mod tests {
435440
L::Target: 'static + Logger,
436441
{
437442
fn persist_manager(&self, channel_manager: &ChannelManager<Signer, M, T, K, F, L>) -> Result<(), std::io::Error> {
438-
FilesystemPersister::persist_manager(self.data_dir.clone(), channel_manager)
443+
match self.manager_error {
444+
None => FilesystemPersister::persist_manager(self.data_dir.clone(), channel_manager),
445+
Some((error, message)) => Err(std::io::Error::new(error, message)),
446+
}
439447
}
440448

441449
fn persist_graph(&self, network_graph: &NetworkGraph) -> Result<(), std::io::Error> {
@@ -652,28 +660,8 @@ mod tests {
652660
let nodes = create_nodes(2, "test_persist_error".to_string());
653661
open_channel!(nodes[0], nodes[1], 100000);
654662

655-
struct ChannelManagerErrorPersister {
656-
data_dir: String,
657-
}
658-
659-
impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L:Deref> super::Persister<Signer, M, T, K, F, L> for ChannelManagerErrorPersister where
660-
M::Target: 'static + chain::Watch<Signer>,
661-
T::Target: 'static + BroadcasterInterface,
662-
K::Target: 'static + KeysInterface<Signer = Signer>,
663-
F::Target: 'static + FeeEstimator,
664-
L::Target: 'static + Logger,
665-
{
666-
fn persist_manager(&self, _channel_manager: &ChannelManager<Signer, M, T, K, F, L>) -> Result<(), std::io::Error> {
667-
Err(std::io::Error::new(std::io::ErrorKind::Other, "test"))
668-
}
669-
670-
fn persist_graph(&self, network_graph: &NetworkGraph) -> Result<(), std::io::Error> {
671-
FilesystemPersister::persist_network_graph(self.data_dir.clone(), network_graph)
672-
}
673-
}
674-
675663
let data_dir = nodes[0].persister.get_data_dir();
676-
let persister = ChannelManagerErrorPersister{ data_dir };
664+
let persister = Persister::new(data_dir).with_manager_error(std::io::ErrorKind::Other, "test");
677665
let event_handler = |_: &_| {};
678666
let bg_processor = BackgroundProcessor::start(persister, event_handler, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), nodes[0].net_graph_msg_handler.clone(), nodes[0].peer_manager.clone(), nodes[0].logger.clone());
679667
match bg_processor.join() {

0 commit comments

Comments
 (0)