From 9eb3030b1ffc23c0969a5ce35d755d8afaf99af7 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 12 Apr 2023 14:04:01 +0200 Subject: [PATCH] fix(relay): ensure stable `connect` test With the changes from #3767, we made the `connect` test flaky because the `Swarm` was fully passed to the future and thus dropped as soon as the connection was established. We pass a mutable reference instead which keeps the `Swarm` alive. Pull-Request: #3780. --- protocols/relay/tests/lib.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/protocols/relay/tests/lib.rs b/protocols/relay/tests/lib.rs index da485748..92538549 100644 --- a/protocols/relay/tests/lib.rs +++ b/protocols/relay/tests/lib.rs @@ -210,12 +210,16 @@ fn connect() { src.dial(dst_addr).unwrap(); pool.run_until(futures::future::join( - connection_established_to(src, relay_peer_id, dst_peer_id), - connection_established_to(dst, relay_peer_id, src_peer_id), + connection_established_to(&mut src, relay_peer_id, dst_peer_id), + connection_established_to(&mut dst, relay_peer_id, src_peer_id), )); } -async fn connection_established_to(mut swarm: Swarm, relay_peer_id: PeerId, other: PeerId) { +async fn connection_established_to( + swarm: &mut Swarm, + relay_peer_id: PeerId, + other: PeerId, +) { loop { match swarm.select_next_some().await { SwarmEvent::Dialing(peer_id) if peer_id == relay_peer_id => {}