From 1a63c92589abd54a59aba79e5e00bd61200cf904 Mon Sep 17 00:00:00 2001 From: Alex Ostrovski Date: Tue, 31 Oct 2023 16:15:48 +0200 Subject: [PATCH 1/2] Fix race condition in `getting_blocks_from_peers` test --- node/actors/network/src/gossip/tests.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/node/actors/network/src/gossip/tests.rs b/node/actors/network/src/gossip/tests.rs index a5156284..0a0d6ccb 100644 --- a/node/actors/network/src/gossip/tests.rs +++ b/node/actors/network/src/gossip/tests.rs @@ -505,7 +505,7 @@ async fn getting_blocks_from_peers(node_count: usize, gossip_peers: usize) { let (network_pipe, dispatcher_pipe) = pipe::new(); let (node_stop_sender, node_stop_receiver) = oneshot::channel::<()>(); s.spawn_bg(async { - scope::run!(ctx, |ctx, s| async { + let result = 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, @@ -515,7 +515,14 @@ async fn getting_blocks_from_peers(node_count: usize, gossip_peers: usize) { node_stop_receiver.recv_or_disconnected(ctx).await?.ok(); Ok(()) }) - .await + .await; + + match result { + Ok(()) => Ok(()), + Err(err) if err.root_cause().is::() => Ok(()), + // ^ Test has successfully finished + Err(err) => Err(err), + } }); (node, node_stop_sender, dispatcher_pipe.send) }); From bdfeb2a3ad3e7fa290e59991cd64f0cf2b69f87c Mon Sep 17 00:00:00 2001 From: Alex Ostrovski Date: Thu, 2 Nov 2023 12:07:09 +0200 Subject: [PATCH 2/2] Remove test timeout in `getting_blocks_from_peers` --- node/actors/network/src/gossip/tests.rs | 30 ++++++++----------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/node/actors/network/src/gossip/tests.rs b/node/actors/network/src/gossip/tests.rs index 0a0d6ccb..77ad9f63 100644 --- a/node/actors/network/src/gossip/tests.rs +++ b/node/actors/network/src/gossip/tests.rs @@ -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(); @@ -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 { @@ -505,24 +502,16 @@ async fn getting_blocks_from_peers(node_count: usize, gossip_peers: usize) { let (network_pipe, dispatcher_pipe) = pipe::new(); let (node_stop_sender, node_stop_receiver) = oneshot::channel::<()>(); s.spawn_bg(async { - let result = scope::run!(ctx, |ctx, s| 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; - - match result { - Ok(()) => Ok(()), - Err(err) if err.root_cause().is::() => Ok(()), - // ^ Test has successfully finished - Err(err) => Err(err), - } + .await }); (node, node_stop_sender, dispatcher_pipe.send) }); @@ -585,7 +574,7 @@ async fn run_get_block_dispatcher( ctx: &ctx::Ctx, mut receiver: channel::UnboundedReceiver, block: FinalBlock, -) -> anyhow::Result<()> { +) { while let Ok(message) = receiver.recv(ctx).await { match message { io::OutputMessage::SyncBlocks(io::SyncBlocksRequest::GetBlock { @@ -598,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