e2e: Replace the hardcoded 1-second sleep in `test_connection_crossing` with polling loop
Avoid relying on a thread sleep to wait for the nodes to connect. Instead rely on the connection condition being established by using a polling loop. The loop is controlled by a number of iterations, panicking if the number of iterations is exceeded.
This commit is contained in:
parent
bfb54bf4be
commit
802e4726e3
|
|
@ -906,17 +906,26 @@ fn test_connection_crossing() {
|
||||||
assert_matches!(r2, ConnectResult::Connected);
|
assert_matches!(r2, ConnectResult::Connected);
|
||||||
}
|
}
|
||||||
|
|
||||||
thread::sleep(time::Duration::from_secs(1));
|
let mut iterations = 0;
|
||||||
|
let (alice_s, bob_s, s1, s2) = loop {
|
||||||
|
let alice_s = alice.handle.sessions().unwrap();
|
||||||
|
let bob_s = bob.handle.sessions().unwrap();
|
||||||
|
|
||||||
let alice_s = alice.handle.sessions().unwrap();
|
let s1 = alice_s.iter().find(|s| s.nid == bob.id).cloned();
|
||||||
let bob_s = bob.handle.sessions().unwrap();
|
let s2 = bob_s.iter().find(|s| s.nid == alice.id).cloned();
|
||||||
|
|
||||||
// Both sessions are established.
|
if let (Some(s1), Some(s2)) = (s1, s2) {
|
||||||
let s1 = alice_s.iter().find(|s| s.nid == bob.id).unwrap();
|
// Wait until both sessions are fully connected
|
||||||
let s2 = bob_s.iter().find(|s| s.nid == alice.id).unwrap();
|
if s1.state.is_connected() && s2.state.is_connected() {
|
||||||
|
break (alice_s, bob_s, s1, s2);
|
||||||
log::debug!(target: "test", "{:?}", alice.handle.sessions());
|
}
|
||||||
log::debug!(target: "test", "{:?}", bob.handle.sessions());
|
}
|
||||||
|
iterations += 1;
|
||||||
|
if iterations >= 100 {
|
||||||
|
panic!("Timeout waiting for sessions to connect");
|
||||||
|
}
|
||||||
|
thread::sleep(time::Duration::from_millis(50));
|
||||||
|
};
|
||||||
|
|
||||||
// We assert that they have opposite link directions.
|
// We assert that they have opposite link directions.
|
||||||
// In a true simultaneous crossing, the preferred peer wins the Outbound link.
|
// In a true simultaneous crossing, the preferred peer wins the Outbound link.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue