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};
|
use std::{fmt::Debug, sync::Mutex};
|
||||||
|
|
||||||
//crates
|
//crates
|
||||||
use fraction::Fraction;
|
use fraction::{Fraction, One};
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
|
|
||||||
static NET_PORT: Lazy<Mutex<u16>> = Lazy::new(|| Mutex::new(thread_rng().gen_range(8000, 10000)));
|
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)]
|
#[derive(Clone)]
|
||||||
pub struct ConsensusConfig {
|
pub struct ConsensusConfig {
|
||||||
pub n_participants: usize,
|
pub n_participants: usize,
|
||||||
|
|
|
@ -1,26 +1,17 @@
|
||||||
use fraction::{Fraction, One};
|
|
||||||
use nomos_cli::{
|
use nomos_cli::{
|
||||||
cmds::{disseminate::Disseminate, Command},
|
cmds::{disseminate::Disseminate, Command},
|
||||||
da::disseminate::{DaProtocolChoice, FullReplicationSettings, Protocol, ProtocolSettings},
|
da::disseminate::{DaProtocolChoice, FullReplicationSettings, Protocol, ProtocolSettings},
|
||||||
};
|
};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tempfile::NamedTempFile;
|
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;
|
const TIMEOUT_SECS: u64 = 20;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn disseminate_blob() {
|
async fn disseminate_blob() {
|
||||||
let (_mixnodes, mixnet_config) = MixNode::spawn_nodes(2).await;
|
let (_mixnodes, mixnet_config) = MixNode::spawn_nodes(2).await;
|
||||||
let mut nodes = NomosNode::spawn_nodes(SpawnConfig::Chain {
|
let mut nodes = NomosNode::spawn_nodes(SpawnConfig::chain_happy(2, mixnet_config)).await;
|
||||||
consensus: ConsensusConfig {
|
|
||||||
n_participants: 2,
|
|
||||||
threshold: Fraction::one(),
|
|
||||||
timeout: Duration::from_secs(10),
|
|
||||||
},
|
|
||||||
mixnet: mixnet_config,
|
|
||||||
})
|
|
||||||
.await;
|
|
||||||
|
|
||||||
// kill the node so that we can reuse its network config
|
// kill the node so that we can reuse its network config
|
||||||
nodes[1].stop();
|
nodes[1].stop();
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
use consensus_engine::{Qc, View};
|
use consensus_engine::{Qc, View};
|
||||||
use fraction::{Fraction, One};
|
|
||||||
use futures::stream::{self, StreamExt};
|
use futures::stream::{self, StreamExt};
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tests::{ConsensusConfig, MixNode, Node, NomosNode, SpawnConfig};
|
use tests::{MixNode, Node, NomosNode, SpawnConfig};
|
||||||
|
|
||||||
const TARGET_VIEW: View = View::new(20);
|
const TARGET_VIEW: View = View::new(20);
|
||||||
|
|
||||||
|
@ -77,45 +76,21 @@ async fn happy_test(nodes: &[NomosNode]) {
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn two_nodes_happy() {
|
async fn two_nodes_happy() {
|
||||||
let (_mixnodes, mixnet_config) = MixNode::spawn_nodes(2).await;
|
let (_mixnodes, mixnet_config) = MixNode::spawn_nodes(2).await;
|
||||||
let nodes = NomosNode::spawn_nodes(SpawnConfig::Chain {
|
let nodes = NomosNode::spawn_nodes(SpawnConfig::chain_happy(2, mixnet_config)).await;
|
||||||
consensus: ConsensusConfig {
|
|
||||||
n_participants: 2,
|
|
||||||
threshold: Fraction::one(),
|
|
||||||
timeout: Duration::from_secs(10),
|
|
||||||
},
|
|
||||||
mixnet: mixnet_config,
|
|
||||||
})
|
|
||||||
.await;
|
|
||||||
happy_test(&nodes).await;
|
happy_test(&nodes).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn ten_nodes_happy() {
|
async fn ten_nodes_happy() {
|
||||||
let (_mixnodes, mixnet_config) = MixNode::spawn_nodes(3).await;
|
let (_mixnodes, mixnet_config) = MixNode::spawn_nodes(3).await;
|
||||||
let nodes = NomosNode::spawn_nodes(SpawnConfig::Chain {
|
let nodes = NomosNode::spawn_nodes(SpawnConfig::chain_happy(10, mixnet_config)).await;
|
||||||
consensus: ConsensusConfig {
|
|
||||||
n_participants: 10,
|
|
||||||
threshold: Fraction::one(),
|
|
||||||
timeout: Duration::from_secs(10),
|
|
||||||
},
|
|
||||||
mixnet: mixnet_config,
|
|
||||||
})
|
|
||||||
.await;
|
|
||||||
happy_test(&nodes).await;
|
happy_test(&nodes).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_get_block() {
|
async fn test_get_block() {
|
||||||
let (_mixnodes, mixnet_config) = MixNode::spawn_nodes(3).await;
|
let (_mixnodes, mixnet_config) = MixNode::spawn_nodes(3).await;
|
||||||
let nodes = NomosNode::spawn_nodes(SpawnConfig::Chain {
|
let nodes = NomosNode::spawn_nodes(SpawnConfig::chain_happy(2, mixnet_config)).await;
|
||||||
consensus: ConsensusConfig {
|
|
||||||
n_participants: 2,
|
|
||||||
threshold: Fraction::one(),
|
|
||||||
timeout: Duration::from_secs(10),
|
|
||||||
},
|
|
||||||
mixnet: mixnet_config,
|
|
||||||
})
|
|
||||||
.await;
|
|
||||||
happy_test(&nodes).await;
|
happy_test(&nodes).await;
|
||||||
let id = nodes[0].consensus_info().await.committed_blocks[0];
|
let id = nodes[0].consensus_info().await.committed_blocks[0];
|
||||||
tokio::time::timeout(Duration::from_secs(10), async {
|
tokio::time::timeout(Duration::from_secs(10), async {
|
||||||
|
|
Loading…
Reference in New Issue