Skip to content

Commit

Permalink
Add test for concurrent connection handling
Browse files Browse the repository at this point in the history
... we check that we can successfully issue concurrent connection
attempts, which all succeed.
  • Loading branch information
tnull committed Apr 25, 2024
1 parent 9c8be40 commit 2d9fe95
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/integration_tests_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,33 @@ fn do_connection_restart_behavior(persist: bool) {
assert!(node_b.list_peers().is_empty());
}
}

#[test]
fn concurrent_connections_succeed() {
let (_bitcoind, electrsd) = setup_bitcoind_and_electrsd();
let (node_a, node_b) = setup_two_nodes(&electrsd, false);

let node_a = Arc::new(node_a);
let node_b = Arc::new(node_b);

let node_id_b = node_b.node_id();
let node_addr_b = node_b.listening_addresses().unwrap().first().unwrap().clone();

while !node_b.status().is_listening {
std::thread::sleep(std::time::Duration::from_millis(10));
}

let mut handles = Vec::new();
for _ in 0..10 {
let thread_node = Arc::clone(&node_a);
let thread_addr = node_addr_b.clone();
let handle = std::thread::spawn(move || {
thread_node.connect(node_id_b, thread_addr, false).unwrap();
});
handles.push(handle);
}

for h in handles {
h.join().unwrap();
}
}

0 comments on commit 2d9fe95

Please sign in to comment.