From 5e520ae194a9b98d9b483f16275b0a1d0ba77e34 Mon Sep 17 00:00:00 2001 From: Youngjoon Lee Date: Tue, 31 Oct 2023 00:39:02 +0900 Subject: [PATCH] Set consensus timeout conservatively for happy-path integration tests (#492) --- tests/src/lib.rs | 20 +++++++++++++++++++- tests/src/tests/cli.rs | 13 ++----------- tests/src/tests/happy.rs | 33 ++++----------------------------- 3 files changed, 25 insertions(+), 41 deletions(-) diff --git a/tests/src/lib.rs b/tests/src/lib.rs index ad0f514c..b9222ccb 100644 --- a/tests/src/lib.rs +++ b/tests/src/lib.rs @@ -11,7 +11,7 @@ use std::time::Duration; use std::{fmt::Debug, sync::Mutex}; //crates -use fraction::Fraction; +use fraction::{Fraction, One}; use rand::{thread_rng, Rng}; static NET_PORT: Lazy> = Lazy::new(|| Mutex::new(thread_rng().gen_range(8000, 10000))); @@ -47,6 +47,24 @@ pub enum SpawnConfig { }, } +impl SpawnConfig { + // Returns a SpawnConfig::Chain with proper configurations for happy-path tests + pub fn chain_happy(n_participants: usize, mixnet_config: MixnetConfig) -> Self { + Self::Chain { + consensus: ConsensusConfig { + n_participants, + // All nodes are expected to be responsive in happy-path tests. + threshold: Fraction::one(), + // Set the timeout conservatively + // since nodes should be spawned sequentially in the chain topology + // and it takes 1+ secs for each nomos-node to be started. + timeout: Duration::from_millis(n_participants as u64 * 2500), + }, + mixnet: mixnet_config, + } + } +} + #[derive(Clone)] pub struct ConsensusConfig { pub n_participants: usize, diff --git a/tests/src/tests/cli.rs b/tests/src/tests/cli.rs index 7e5828be..39f14a5b 100644 --- a/tests/src/tests/cli.rs +++ b/tests/src/tests/cli.rs @@ -1,26 +1,17 @@ -use fraction::{Fraction, One}; use nomos_cli::{ cmds::{disseminate::Disseminate, Command}, da::disseminate::{DaProtocolChoice, FullReplicationSettings, Protocol, ProtocolSettings}, }; use std::time::Duration; use tempfile::NamedTempFile; -use tests::{nodes::nomos::Pool, ConsensusConfig, MixNode, Node, NomosNode, SpawnConfig}; +use tests::{nodes::nomos::Pool, MixNode, Node, NomosNode, SpawnConfig}; const TIMEOUT_SECS: u64 = 20; #[tokio::test] async fn disseminate_blob() { let (_mixnodes, mixnet_config) = MixNode::spawn_nodes(2).await; - let mut nodes = NomosNode::spawn_nodes(SpawnConfig::Chain { - consensus: ConsensusConfig { - n_participants: 2, - threshold: Fraction::one(), - timeout: Duration::from_secs(10), - }, - mixnet: mixnet_config, - }) - .await; + let mut nodes = NomosNode::spawn_nodes(SpawnConfig::chain_happy(2, mixnet_config)).await; // kill the node so that we can reuse its network config nodes[1].stop(); diff --git a/tests/src/tests/happy.rs b/tests/src/tests/happy.rs index 359877d9..c9fa64e8 100644 --- a/tests/src/tests/happy.rs +++ b/tests/src/tests/happy.rs @@ -1,9 +1,8 @@ use consensus_engine::{Qc, View}; -use fraction::{Fraction, One}; use futures::stream::{self, StreamExt}; use std::collections::HashSet; use std::time::Duration; -use tests::{ConsensusConfig, MixNode, Node, NomosNode, SpawnConfig}; +use tests::{MixNode, Node, NomosNode, SpawnConfig}; const TARGET_VIEW: View = View::new(20); @@ -77,45 +76,21 @@ async fn happy_test(nodes: &[NomosNode]) { #[tokio::test] async fn two_nodes_happy() { let (_mixnodes, mixnet_config) = MixNode::spawn_nodes(2).await; - let nodes = NomosNode::spawn_nodes(SpawnConfig::Chain { - consensus: ConsensusConfig { - n_participants: 2, - threshold: Fraction::one(), - timeout: Duration::from_secs(10), - }, - mixnet: mixnet_config, - }) - .await; + let nodes = NomosNode::spawn_nodes(SpawnConfig::chain_happy(2, mixnet_config)).await; happy_test(&nodes).await; } #[tokio::test] async fn ten_nodes_happy() { let (_mixnodes, mixnet_config) = MixNode::spawn_nodes(3).await; - let nodes = NomosNode::spawn_nodes(SpawnConfig::Chain { - consensus: ConsensusConfig { - n_participants: 10, - threshold: Fraction::one(), - timeout: Duration::from_secs(10), - }, - mixnet: mixnet_config, - }) - .await; + let nodes = NomosNode::spawn_nodes(SpawnConfig::chain_happy(10, mixnet_config)).await; happy_test(&nodes).await; } #[tokio::test] async fn test_get_block() { let (_mixnodes, mixnet_config) = MixNode::spawn_nodes(3).await; - let nodes = NomosNode::spawn_nodes(SpawnConfig::Chain { - consensus: ConsensusConfig { - n_participants: 2, - threshold: Fraction::one(), - timeout: Duration::from_secs(10), - }, - mixnet: mixnet_config, - }) - .await; + let nodes = NomosNode::spawn_nodes(SpawnConfig::chain_happy(2, mixnet_config)).await; happy_test(&nodes).await; let id = nodes[0].consensus_info().await.committed_blocks[0]; tokio::time::timeout(Duration::from_secs(10), async {