Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix flaky connect #9113

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions crates/e2e-test-utils/src/network.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use futures_util::StreamExt;
use reth::network::{NetworkEvent, NetworkEvents, NetworkHandle, PeersInfo};
use reth::{
network::{NetworkEvent, NetworkEvents, NetworkHandle, PeersInfo},
rpc::types::PeerId,
};
use reth_chainspec::net::NodeRecord;
use reth_tokio_util::EventStream;
use reth_tracing::tracing::info;
Expand Down Expand Up @@ -32,13 +35,17 @@ impl NetworkTestContext {
self.network.local_node_record()
}

/// Expects a session to be established
pub async fn expect_session(&mut self) {
match self.network_events.next().await {
Some(NetworkEvent::SessionEstablished { remote_addr, .. }) => {
info!(?remote_addr, "Session established")
/// Awaits the next event for an established session.
pub async fn next_session_established(&mut self) -> Option<PeerId> {
while let Some(ev) = self.network_events.next().await {
match ev {
NetworkEvent::SessionEstablished { peer_id, .. } => {
info!("Session established with peer: {:?}", peer_id);
return Some(peer_id)
}
_ => continue,
}
ev => panic!("Expected session established event, got: {ev:?}"),
}
None
}
}
6 changes: 3 additions & 3 deletions crates/e2e-test-utils/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ where
})
}

/// Establish a connection to the node
pub async fn connect(&mut self, node: &mut NodeTestContext<Node>) {
self.network.add_peer(node.network.record()).await;
node.network.add_peer(self.network.record()).await;
node.network.expect_session().await;
self.network.expect_session().await;
node.network.next_session_established().await;
self.network.next_session_established().await;
}

/// Advances the chain `length` blocks.
Expand Down
Loading