Skip to content

Commit a1c1b02

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 d9655b0 commit a1c1b02

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

+29
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,35 @@ mod tests {
12371237
}
12381238
}
12391239

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

0 commit comments

Comments
 (0)