Skip to content

Commit 445f21b

Browse files
committed
Modify pruning test to use recv timeouts.
1 parent 8b3f697 commit 445f21b

File tree

1 file changed

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

1 file changed

+26
-24
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ mod tests {
385385
use std::ops::Deref;
386386
use std::path::PathBuf;
387387
use std::sync::{Arc, Mutex};
388+
use std::sync::mpsc::SyncSender;
388389
use std::time::Duration;
389390
use super::{BackgroundProcessor, FRESHNESS_TIMER};
390391

@@ -427,21 +428,27 @@ mod tests {
427428
struct Persister {
428429
data_dir: String,
429430
graph_error: Option<(std::io::ErrorKind, &'static str)>,
431+
graph_sender: Option<SyncSender<NetworkGraph>>,
430432
manager_error: Option<(std::io::ErrorKind, &'static str)>
431433
}
432434

433435
impl Persister {
434436
fn new(data_dir: String) -> Self {
435-
Self { data_dir, graph_error: None, manager_error: None }
437+
Self { data_dir, graph_error: None, manager_error: None, graph_sender: None }
436438
}
437439

438440
fn with_graph_error(self, error: std::io::ErrorKind, message: &'static str) -> Self {
439441
Self { graph_error: Some((error, message)), ..self }
440442
}
441443

444+
fn with_graph_sender(self, sender: SyncSender<NetworkGraph>) -> Self {
445+
Self { graph_sender: Some(sender), ..self }
446+
}
447+
442448
fn with_manager_error(self, error: std::io::ErrorKind, message: &'static str) -> Self {
443449
Self { manager_error: Some((error, message)), ..self }
444450
}
451+
445452
}
446453

447454
impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L:Deref> super::Persister<Signer, M, T, K, F, L> for Persister where
@@ -459,6 +466,10 @@ mod tests {
459466
}
460467

461468
fn persist_graph(&self, network_graph: &NetworkGraph) -> Result<(), std::io::Error> {
469+
if let Some(sender) = &self.graph_sender {
470+
sender.send(network_graph.clone());
471+
};
472+
462473
match self.graph_error {
463474
None => FilesystemPersister::persist_network_graph(self.data_dir.clone(), network_graph),
464475
Some((error, message)) => Err(std::io::Error::new(error, message)),
@@ -762,40 +773,31 @@ mod tests {
762773
let mut nodes = create_nodes(2, "test_not_pruning_network_graph_until_graph_sync_completion".to_string());
763774
let channel_value = 100000;
764775
let data_dir = nodes[0].persister.get_data_dir();
765-
let persister = Persister::new(data_dir.clone());
776+
let (sender, receiver) = std::sync::mpsc::sync_channel(1);
777+
let persister = Persister::new(data_dir.clone()).with_graph_sender(sender);
766778
let network_graph = nodes[0].network_graph.clone();
767779
let features = ChannelFeatures::empty();
768780
network_graph.update_channel_from_partial_announcement(42, 53, features, nodes[0].node.get_our_node_id(), nodes[1].node.get_our_node_id());
769781
let original_graph_description = network_graph.to_string();
770782
assert!(original_graph_description.contains("42: features: 0000, node_one:"));
771783

772-
let (sender, receiver) = std::sync::mpsc::sync_channel(1);
773-
let event_handler = move |event: &Event| {
774-
sender.send(handle_funding_generation_ready!(event, channel_value)).unwrap();
775-
};
784+
let event_handler = |_: &_| {};
776785
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(), true, nodes[0].logger.clone());
777786

778-
for i in 0..EVENT_DEADLINE {
779-
std::thread::sleep(Duration::from_secs(1));
780-
let current_graph_description = network_graph.to_string();
781-
assert_eq!(current_graph_description, original_graph_description)
782-
}
787+
let reception_result = receiver
788+
.recv_timeout(Duration::from_secs(EVENT_DEADLINE));
789+
assert!(reception_result.is_err());
783790

784791
bg_processor.graph_sync_complete();
785792

786-
let mut seconds_slept = 0;
787-
loop {
788-
assert!(seconds_slept < 3);
789-
std::thread::sleep(Duration::from_secs(1));
790-
seconds_slept += 1;
791-
let current_graph_description = network_graph.to_string();
792-
if current_graph_description != original_graph_description {
793-
assert_eq!(current_graph_description.len(), 31);
794-
assert!(!current_graph_description.contains("node_one:"));
795-
assert!(!current_graph_description.contains("node_two:"));
796-
break
797-
}
798-
}
793+
let graph = receiver
794+
.recv_timeout(Duration::from_secs(EVENT_DEADLINE))
795+
.expect("SpendableOutputs not handled within deadline");
796+
let current_graph_description = network_graph.to_string();
797+
assert_ne!(current_graph_description, original_graph_description);
798+
assert_eq!(current_graph_description.len(), 31);
799+
assert!(!current_graph_description.contains("node_one:"));
800+
assert!(!current_graph_description.contains("node_two:"));
799801
}
800802

801803
#[test]

0 commit comments

Comments
 (0)