Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
e2e: Replace the hardcoded 1-second sleep in `test_connection_crossing` with polling loop
Adrian Duke committed 7 days ago
commit 802e4726e3daa1353b79dcd1d697e2634f2c673c
parent bfb54bf
1 file changed +20 -11
modified crates/radicle-node/src/tests/e2e.rs
@@ -906,17 +906,26 @@ fn test_connection_crossing() {
        assert_matches!(r2, ConnectResult::Connected);
    }

-
    thread::sleep(time::Duration::from_secs(1));
-

-
    let alice_s = alice.handle.sessions().unwrap();
-
    let bob_s = bob.handle.sessions().unwrap();
-

-
    // Both sessions are established.
-
    let s1 = alice_s.iter().find(|s| s.nid == bob.id).unwrap();
-
    let s2 = bob_s.iter().find(|s| s.nid == alice.id).unwrap();
-

-
    log::debug!(target: "test", "{:?}", alice.handle.sessions());
-
    log::debug!(target: "test", "{:?}", bob.handle.sessions());
+
    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 s1 = alice_s.iter().find(|s| s.nid == bob.id).cloned();
+
        let s2 = bob_s.iter().find(|s| s.nid == alice.id).cloned();
+

+
        if let (Some(s1), Some(s2)) = (s1, s2) {
+
            // Wait until both sessions are fully connected
+
            if s1.state.is_connected() && s2.state.is_connected() {
+
                break (alice_s, bob_s, s1, s2);
+
            }
+
        }
+
        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.
    // In a true simultaneous crossing, the preferred peer wins the Outbound link.