Skip to content

Commit f26fad9

Browse files
committed
Add test for concurrent connection handling
... we check that we can successfully issue concurrent connection attempts, which all succeed.
1 parent 8d8cd21 commit f26fad9

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
@@ -331,3 +331,33 @@ fn do_connection_restart_behavior(persist: bool) {
331331
assert!(node_b.list_peers().is_empty());
332332
}
333333
}
334+
335+
#[test]
336+
fn concurrent_connections_succeed() {
337+
let (_bitcoind, electrsd) = setup_bitcoind_and_electrsd();
338+
let (node_a, node_b) = setup_two_nodes(&electrsd, false);
339+
340+
let node_a = Arc::new(node_a);
341+
let node_b = Arc::new(node_b);
342+
343+
let node_id_b = node_b.node_id();
344+
let node_addr_b = node_b.listening_addresses().unwrap().first().unwrap().clone();
345+
346+
while !node_b.status().is_listening {
347+
std::thread::sleep(std::time::Duration::from_millis(10));
348+
}
349+
350+
let mut handles = Vec::new();
351+
for _ in 0..10 {
352+
let thread_node = Arc::clone(&node_a);
353+
let thread_addr = node_addr_b.clone();
354+
let handle = std::thread::spawn(move || {
355+
thread_node.connect(node_id_b, thread_addr, false).unwrap();
356+
});
357+
handles.push(handle);
358+
}
359+
360+
for h in handles {
361+
h.join().unwrap();
362+
}
363+
}

0 commit comments

Comments
 (0)