Skip to content

Commit 0618fbe

Browse files
committed
Add an async version of BP's test_channel_manager_persist_error
This gives us coverage of an async BP returning an error.
1 parent 85a17a3 commit 0618fbe

File tree

1 file changed

+29
-0
lines changed
  • lightning-background-processor/src

1 file changed

+29
-0
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,35 @@ mod tests {
12351235
}
12361236
}
12371237

1238+
#[tokio::test]
1239+
#[cfg(feature = "futures")]
1240+
async fn test_channel_manager_persist_error_async() {
1241+
// Test that if we encounter an error during manager persistence, the thread panics.
1242+
let nodes = create_nodes(2, "test_persist_error_sync".to_string());
1243+
open_channel!(nodes[0], nodes[1], 100000);
1244+
1245+
let data_dir = nodes[0].persister.get_data_dir();
1246+
let persister = Arc::new(Persister::new(data_dir).with_manager_error(std::io::ErrorKind::Other, "test"));
1247+
1248+
let bp_future = super::process_events_async(
1249+
persister, |_: _| {async {}}, nodes[0].chain_monitor.clone(), nodes[0].node.clone(),
1250+
nodes[0].rapid_gossip_sync(), nodes[0].peer_manager.clone(), nodes[0].logger.clone(),
1251+
Some(nodes[0].scorer.clone()), move |dur: Duration| {
1252+
Box::pin(async move {
1253+
tokio::time::sleep(dur).await;
1254+
false // Never exit
1255+
})
1256+
}, false,
1257+
);
1258+
match bp_future.await {
1259+
Ok(_) => panic!("Expected error persisting manager"),
1260+
Err(e) => {
1261+
assert_eq!(e.kind(), std::io::ErrorKind::Other);
1262+
assert_eq!(e.get_ref().unwrap().to_string(), "test");
1263+
},
1264+
}
1265+
}
1266+
12381267
#[test]
12391268
fn test_network_graph_persist_error() {
12401269
// Test that if we encounter an error during network graph persistence, an error gets returned.

0 commit comments

Comments
 (0)