From 2e6365bb95c3fdcd790a237b5b2ec55885e8d694 Mon Sep 17 00:00:00 2001 From: Youngjoon Lee <5462944+youngjoon-lee@users.noreply.github.com> Date: Tue, 28 Nov 2023 09:02:24 +0900 Subject: [PATCH] Use 2x timeout for integration tests in Codecov CI (#533) --- .github/workflows/build-test.yml | 16 ++++++++++++++-- .github/workflows/codecov.yml | 2 ++ tests/src/lib.rs | 15 ++++++++++++++- tests/src/nodes/nomos.rs | 4 ++-- tests/src/tests/cli.rs | 6 ++++-- tests/src/tests/happy.rs | 4 ++-- tests/src/tests/unhappy.rs | 6 +++--- 7 files changed, 41 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index e195fdfa..0977a2f6 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -64,11 +64,23 @@ jobs: - name: Setup build environment (Windows) if: matrix.os == 'windows-latest' uses: ./.github/actions/mingw-env - - uses: actions-rs/cargo@v1 + - name: Cargo build + uses: actions-rs/cargo@v1 with: command: build args: --all --no-default-features --features ${{ matrix.feature }} - - uses: actions-rs/cargo@v1 + - name: Cargo test (Other OSes) + if: matrix.os != 'windows-latest' + uses: actions-rs/cargo@v1 + with: + command: test + args: --all --no-default-features --features ${{ matrix.feature }} + - name: Cargo test (Windows) + if: matrix.os == 'windows-latest' + uses: actions-rs/cargo@v1 + env: + # Because Windows runners in Github Actions tend to be slow. + SLOW_TEST_ENV: true with: command: test args: --all --no-default-features --features ${{ matrix.feature }} diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index b6044977..68fafe3c 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -35,6 +35,8 @@ jobs: cargo test --no-default-features --features libp2p mkdir /tmp/cov; grcov . --binary-path ./target/debug/ -s . -t lcov --branch --ignore-not-existing --ignore '../*' --ignore "/*" -o /tmp/cov/tests.lcov; + env: + SLOW_TEST_ENV: true - uses: actions/upload-artifact@v3 if: failure() with: diff --git a/tests/src/lib.rs b/tests/src/lib.rs index b9222ccb..cbc6da5b 100644 --- a/tests/src/lib.rs +++ b/tests/src/lib.rs @@ -5,8 +5,10 @@ pub use nodes::MixNode; pub use nodes::NomosNode; use once_cell::sync::Lazy; +use std::env; // std use std::net::TcpListener; +use std::ops::Mul; use std::time::Duration; use std::{fmt::Debug, sync::Mutex}; @@ -15,6 +17,8 @@ use fraction::{Fraction, One}; use rand::{thread_rng, Rng}; static NET_PORT: Lazy> = Lazy::new(|| Mutex::new(thread_rng().gen_range(8000, 10000))); +static IS_SLOW_TEST_ENV: Lazy = + Lazy::new(|| env::var("SLOW_TEST_ENV").is_ok_and(|s| s == "true")); pub fn get_available_port() -> u16 { let mut port = NET_PORT.lock().unwrap(); @@ -25,6 +29,15 @@ pub fn get_available_port() -> u16 { *port } +/// In slow test environments like Codecov, use 2x timeout. +pub fn adjust_timeout(d: Duration) -> Duration { + if *IS_SLOW_TEST_ENV { + d.mul(2) + } else { + d + } +} + #[async_trait::async_trait] pub trait Node: Sized { type ConsensusInfo: Debug + Clone + PartialEq; @@ -58,7 +71,7 @@ impl SpawnConfig { // 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), + timeout: adjust_timeout(Duration::from_millis(n_participants as u64 * 2500)), }, mixnet: mixnet_config, } diff --git a/tests/src/nodes/nomos.rs b/tests/src/nodes/nomos.rs index cffc8597..a0a90762 100644 --- a/tests/src/nodes/nomos.rs +++ b/tests/src/nodes/nomos.rs @@ -3,7 +3,7 @@ use std::net::SocketAddr; use std::process::{Child, Command, Stdio}; use std::time::Duration; // internal -use crate::{get_available_port, ConsensusConfig, MixnetConfig, Node, SpawnConfig}; +use crate::{adjust_timeout, get_available_port, ConsensusConfig, MixnetConfig, Node, SpawnConfig}; use consensus_engine::overlay::{RandomBeaconState, RoundRobin, TreeOverlay, TreeOverlaySettings}; use consensus_engine::{BlockId, NodeId, Overlay}; use full_replication::Certificate; @@ -89,7 +89,7 @@ impl NomosNode { _tempdir: dir, config, }; - tokio::time::timeout(std::time::Duration::from_secs(10), async { + tokio::time::timeout(adjust_timeout(Duration::from_secs(10)), async { node.wait_online().await }) .await diff --git a/tests/src/tests/cli.rs b/tests/src/tests/cli.rs index 2fbf7ab1..356c02a9 100644 --- a/tests/src/tests/cli.rs +++ b/tests/src/tests/cli.rs @@ -4,7 +4,9 @@ use nomos_cli::{ }; use std::time::Duration; use tempfile::NamedTempFile; -use tests::{get_available_port, nodes::nomos::Pool, MixNode, Node, NomosNode, SpawnConfig}; +use tests::{ + adjust_timeout, get_available_port, nodes::nomos::Pool, MixNode, Node, NomosNode, SpawnConfig, +}; const TIMEOUT_SECS: u64 = 20; @@ -50,7 +52,7 @@ async fn disseminate_blob() { let thread = std::thread::spawn(move || cmd.run().unwrap()); tokio::time::timeout( - Duration::from_secs(TIMEOUT_SECS), + adjust_timeout(Duration::from_secs(TIMEOUT_SECS)), wait_for_cert_in_mempool(&nodes[0]), ) .await diff --git a/tests/src/tests/happy.rs b/tests/src/tests/happy.rs index 5664b728..bd7be3b6 100644 --- a/tests/src/tests/happy.rs +++ b/tests/src/tests/happy.rs @@ -2,7 +2,7 @@ use consensus_engine::{Qc, View}; use futures::stream::{self, StreamExt}; use std::collections::HashSet; use std::time::Duration; -use tests::{MixNode, Node, NomosNode, SpawnConfig}; +use tests::{adjust_timeout, MixNode, Node, NomosNode, SpawnConfig}; const TARGET_VIEW: View = View::new(20); @@ -14,7 +14,7 @@ struct Info { } async fn happy_test(nodes: &[NomosNode]) { - let timeout = std::time::Duration::from_secs(30); + let timeout = adjust_timeout(Duration::from_secs(30)); let timeout = tokio::time::sleep(timeout); tokio::select! { _ = timeout => panic!("timed out waiting for nodes to reach view {}", TARGET_VIEW), diff --git a/tests/src/tests/unhappy.rs b/tests/src/tests/unhappy.rs index 51f83b67..2c4eb787 100644 --- a/tests/src/tests/unhappy.rs +++ b/tests/src/tests/unhappy.rs @@ -2,8 +2,8 @@ use consensus_engine::{Block, NodeId, TimeoutQc, View}; use fraction::Fraction; use futures::stream::{self, StreamExt}; use nomos_consensus::CarnotInfo; -use std::collections::HashSet; -use tests::{ConsensusConfig, MixNode, Node, NomosNode, SpawnConfig}; +use std::{collections::HashSet, time::Duration}; +use tests::{adjust_timeout, ConsensusConfig, MixNode, Node, NomosNode, SpawnConfig}; const TARGET_VIEW: View = View::new(20); const DUMMY_NODE_ID: NodeId = NodeId::new([0u8; 32]); @@ -22,7 +22,7 @@ async fn ten_nodes_one_down() { .await; let mut failed_node = nodes.pop().unwrap(); failed_node.stop(); - let timeout = std::time::Duration::from_secs(120); + let timeout = adjust_timeout(Duration::from_secs(120)); let timeout = tokio::time::sleep(timeout); tokio::select! { _ = timeout => panic!("timed out waiting for nodes to reach view {}", TARGET_VIEW),