Skip to content

Commit 974c0b7

Browse files
committed
Add test for concurrent connection handling
... we check that we can successfully issue concurrent connection attempts, which all succeed.
1 parent 74542c6 commit 974c0b7

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/integration_tests_rust.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,10 @@ fn do_connection_restart_behavior(persist: bool) {
290290
let node_id_b = node_b.node_id();
291291

292292
let node_addr_b = node_b.listening_addresses().unwrap().first().unwrap().clone();
293+
294+
// Sleep a second to allow node_b's listener task to spawn and bind before we try connecting.
293295
std::thread::sleep(std::time::Duration::from_secs(1));
296+
294297
node_a.connect(node_id_b, node_addr_b, persist).unwrap();
295298

296299
let peer_details_a = node_a.list_peers().first().unwrap().clone();
@@ -327,3 +330,32 @@ fn do_connection_restart_behavior(persist: bool) {
327330
assert!(node_b.list_peers().is_empty());
328331
}
329332
}
333+
334+
#[test]
335+
fn concurrent_connections_succeed() {
336+
let (_bitcoind, electrsd) = setup_bitcoind_and_electrsd();
337+
let (node_a, node_b) = setup_two_nodes(&electrsd, false);
338+
339+
let node_a = Arc::new(node_a);
340+
let node_b = Arc::new(node_b);
341+
342+
let node_id_b = node_b.node_id();
343+
let node_addr_b = node_b.listening_addresses().unwrap().first().unwrap().clone();
344+
345+
// Sleep a second to allow node_b's listener task to spawn and bind before we try connecting.
346+
std::thread::sleep(std::time::Duration::from_secs(1));
347+
348+
let mut handles = Vec::new();
349+
for _ in 0..10 {
350+
let thread_node = Arc::clone(&node_a);
351+
let thread_addr = node_addr_b.clone();
352+
let handle = std::thread::spawn(move || {
353+
thread_node.connect(node_id_b, thread_addr, false).unwrap();
354+
});
355+
handles.push(handle);
356+
}
357+
358+
for h in handles {
359+
h.join().unwrap();
360+
}
361+
}

0 commit comments

Comments
 (0)