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

fix: Fix race condition in network tests #20

Merged
merged 2 commits into from
Nov 2, 2023
Merged
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
19 changes: 7 additions & 12 deletions node/actors/network/src/gossip/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ use test_casing::{test_casing, Product};
use tracing::Instrument as _;
use utils::pipe;

const TEST_TIMEOUT: time::Duration = time::Duration::seconds(5);

#[tokio::test]
async fn test_one_connection_per_node() {
concurrency::testonly::abort_on_panic();
Expand Down Expand Up @@ -484,8 +482,7 @@ async fn run_mock_uncoordinated_dispatcher(
async fn getting_blocks_from_peers(node_count: usize, gossip_peers: usize) {
concurrency::testonly::abort_on_panic();

let ctx = &ctx::test_root(&ctx::RealClock).with_timeout(TEST_TIMEOUT);
let ctx = &ctx::test_with_clock(ctx, &ctx::ManualClock::new());
let ctx = &ctx::test_root(&ctx::ManualClock::new());
let rng = &mut ctx.rng();
let mut nodes = testonly::Instance::new(rng, node_count, gossip_peers);
for node in &mut nodes {
Expand All @@ -507,12 +504,11 @@ async fn getting_blocks_from_peers(node_count: usize, gossip_peers: usize) {
s.spawn_bg(async {
scope::run!(ctx, |ctx, s| async {
s.spawn_bg(run_network(ctx, node.state.clone(), network_pipe));
s.spawn_bg(run_get_block_dispatcher(
ctx,
dispatcher_pipe.recv,
block.clone(),
));
node_stop_receiver.recv_or_disconnected(ctx).await?.ok();
s.spawn_bg(async {
run_get_block_dispatcher(ctx, dispatcher_pipe.recv, block.clone()).await;
Ok(())
});
node_stop_receiver.recv_or_disconnected(ctx).await.ok();
Ok(())
})
.await
Expand Down Expand Up @@ -578,7 +574,7 @@ async fn run_get_block_dispatcher(
ctx: &ctx::Ctx,
mut receiver: channel::UnboundedReceiver<io::OutputMessage>,
block: FinalBlock,
) -> anyhow::Result<()> {
) {
while let Ok(message) = receiver.recv(ctx).await {
match message {
io::OutputMessage::SyncBlocks(io::SyncBlocksRequest::GetBlock {
Expand All @@ -591,7 +587,6 @@ async fn run_get_block_dispatcher(
other => panic!("received unexpected message: {other:?}"),
}
}
Ok(())
}

/// When validator node is restarted, it should immediately override
Expand Down
Loading