Skip to content

Commit 206a8e3

Browse files
committed
Add test for concurrent connection handling
... we check that we can successfully issue concurrent connection attempts, which all succeed.
1 parent 4f7c745 commit 206a8e3

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/integration_tests_rust.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,3 +333,33 @@ fn do_connection_restart_behavior(persist: bool) {
333333
assert!(node_b.list_peers().is_empty());
334334
}
335335
}
336+
337+
#[test]
338+
fn concurrent_connections_succeed() {
339+
let (_bitcoind, electrsd) = setup_bitcoind_and_electrsd();
340+
let (node_a, node_b) = setup_two_nodes(&electrsd, false);
341+
342+
let node_a = Arc::new(node_a);
343+
let node_b = Arc::new(node_b);
344+
345+
let node_id_b = node_b.node_id();
346+
let node_addr_b = node_b.listening_addresses().unwrap().first().unwrap().clone();
347+
348+
while !node_b.status().is_listening {
349+
std::thread::sleep(std::time::Duration::from_millis(10));
350+
}
351+
352+
let mut handles = Vec::new();
353+
for _ in 0..10 {
354+
let thread_node = Arc::clone(&node_a);
355+
let thread_addr = node_addr_b.clone();
356+
let handle = std::thread::spawn(move || {
357+
thread_node.connect(node_id_b, thread_addr, false).unwrap();
358+
});
359+
handles.push(handle);
360+
}
361+
362+
for h in handles {
363+
h.join().unwrap();
364+
}
365+
}

0 commit comments

Comments
 (0)