mirror of
https://seed.radicle.dev/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git
synced 2026-11-16 08:10:40 +08:00
Addresses intermittent failures in the `test_connection_crossing` e2e test, which were particularly prevalent on slower CI environments (such as `rust:trixie`). Previously, the test spawned two threads to make Alice and Bob dial each other concurrently and strictly asserted that the "preferred" peer (the one with the higher Node ID) would always win the `Outbound` link direction. However, this assumption is flawed in real-world, OS-level network execution due to two race conditions: 1. Thread Scheduling: One thread could execute and fully establish a connection before the other thread even began processing its dial command. 2. Reactor Event Ordering: A node's reactor might wake up and process an incoming TCP connection from its peer *before* it processes the `Connect` command sent by the test. When it finally processes the `Connect` command, it sees a session already exists and skips dialing entirely. In both scenarios, a true "simultaneous crossing" never occurs. Instead, a standard sequential connection happens, meaning the link direction is dictated by whoever dialed first, not by the "preferred" peer logic. This caused the strict `left: Outbound, right: Inbound` assertions to panic. To fix this, two changes were made: - Introduced a `std::sync::Barrier` to synchronize the two test threads. This forces both threads to wait for each other before calling `.connect()`, maximizing the probability of a true simultaneous dial. - Relaxed the final assertions. Because OS-level TCP handshakes and reactor polling can never guarantee perfect simultaneity, we no longer assert *which* peer gets the `Outbound` link. Instead, we assert the core invariant: that exactly one connection is established between the nodes, and that their link directions are opposite (`s1.link != s2.link`).