From 75b9456e69e3125009008eb96fb0fbbcc8f75409 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 24 May 2023 16:50:00 +0100 Subject: [PATCH] Fix flaky test and error reporting (#7282) * Fix flaky test and error reporting * Address review comments and adjust recv timeouts --- .../node/network/availability-recovery/src/tests.rs | 8 ++++++-- .../node/network/bitfield-distribution/src/tests.rs | 11 ++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/polkadot/node/network/availability-recovery/src/tests.rs b/polkadot/node/network/availability-recovery/src/tests.rs index 5a2f70149f..b9c5abee19 100644 --- a/polkadot/node/network/availability-recovery/src/tests.rs +++ b/polkadot/node/network/availability-recovery/src/tests.rs @@ -172,7 +172,9 @@ async fn overseer_signal( .send(FromOrchestra::Signal(signal)) .timeout(TIMEOUT) .await - .expect("10ms is more than enough for sending signals."); + .unwrap_or_else(|| { + panic!("{}ms is more than enough for sending signals.", TIMEOUT.as_millis()) + }); } async fn overseer_send( @@ -184,7 +186,9 @@ async fn overseer_send( .send(FromOrchestra::Communication { msg }) .timeout(TIMEOUT) .await - .expect("10ms is more than enough for sending messages."); + .unwrap_or_else(|| { + panic!("{}ms is more than enough for sending messages.", TIMEOUT.as_millis()) + }); } async fn overseer_recv( diff --git a/polkadot/node/network/bitfield-distribution/src/tests.rs b/polkadot/node/network/bitfield-distribution/src/tests.rs index f36fd59c35..f1bdca0dc5 100644 --- a/polkadot/node/network/bitfield-distribution/src/tests.rs +++ b/polkadot/node/network/bitfield-distribution/src/tests.rs @@ -41,11 +41,12 @@ use sp_keystore::{testing::MemoryKeystore, Keystore, KeystorePtr}; use std::{iter::FromIterator as _, sync::Arc, time::Duration}; +const TIMEOUT: Duration = Duration::from_millis(50); macro_rules! launch { ($fut:expr) => { - $fut.timeout(Duration::from_millis(10)) - .await - .expect("10ms is more than enough for sending messages.") + $fut.timeout(TIMEOUT).await.unwrap_or_else(|| { + panic!("{}ms is more than enough for sending messages.", TIMEOUT.as_millis()) + }); }; } @@ -220,7 +221,7 @@ fn receive_invalid_signature() { )); // reputation doesn't change due to one_job_per_validator check - assert!(handle.recv().timeout(Duration::from_millis(10)).await.is_none()); + assert!(handle.recv().timeout(TIMEOUT).await.is_none()); launch!(handle_network_msg( &mut ctx, @@ -523,7 +524,7 @@ fn do_not_relay_message_twice() { ); // There shouldn't be any other message - assert!(handle.recv().timeout(Duration::from_millis(10)).await.is_none()); + assert!(handle.recv().timeout(TIMEOUT).await.is_none()); }); }