Set consensus timeout conservatively for happy-path integration tests (#492)
This commit is contained in:
parent
a487d8c7a0
commit
5e520ae194
|
@ -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<Mutex<u16>> = 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,
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue