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 Mar 5, 2024
1 parent 5cd220d commit e56e1c0
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/integration_tests_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,10 @@ fn do_connection_restart_behavior(persist: bool) {
let node_id_b = node_b.node_id();

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

// Sleep a second to allow node_b's listener task to spawn and bind before we try connecting.
std::thread::sleep(std::time::Duration::from_secs(1));

node_a.connect(node_id_b, node_addr_b, persist).unwrap();

let peer_details_a = node_a.list_peers().first().unwrap().clone();
Expand Down Expand Up @@ -327,3 +330,32 @@ 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();

// Sleep a second to allow node_b's listener task to spawn and bind before we try connecting.
std::thread::sleep(std::time::Duration::from_secs(1));

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 e56e1c0

Please sign in to comment.