From 2208702cddb140ee534f1d8c9559e47eb9172ede Mon Sep 17 00:00:00 2001 From: teor Date: Mon, 19 Oct 2020 13:48:09 +1000 Subject: [PATCH 1/5] Enable the zebrad sync tests by default If your test environment does not have DNS or network access, set the ZEBRA_SKIP_NETWORK_TESTS environmental variable to disable these tests. --- zebrad/tests/acceptance.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/zebrad/tests/acceptance.rs b/zebrad/tests/acceptance.rs index 03c02139419..f940eb66090 100644 --- a/zebrad/tests/acceptance.rs +++ b/zebrad/tests/acceptance.rs @@ -460,7 +460,6 @@ fn valid_generated_config(command: &str, expected_output: &str) -> Result<()> { /// If your test environment does not have network access, skip /// this test by setting the `ZEBRA_SKIP_NETWORK_TESTS` env var. #[test] -#[ignore] fn sync_one_checkpoint_mainnet() -> Result<()> { sync_one_checkpoint(Mainnet) } @@ -470,7 +469,6 @@ fn sync_one_checkpoint_mainnet() -> Result<()> { /// If your test environment does not have network access, skip /// this test by setting the `ZEBRA_SKIP_NETWORK_TESTS` env var. #[test] -#[ignore] fn sync_one_checkpoint_testnet() -> Result<()> { sync_one_checkpoint(Testnet) } From c8b3163c99199acda82691950184adcadc2a985e Mon Sep 17 00:00:00 2001 From: teor Date: Mon, 19 Oct 2020 14:03:24 +1000 Subject: [PATCH 2/5] Disable sync test on ubuntu CI runners They don't seem to have DNS or network configured during the tests. Also make capitalisation of step names consistent. --- .github/workflows/ci.yml | 8 ++++++-- .github/workflows/coverage.yml | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aef9225e991..80d3b5171fe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,9 +22,13 @@ jobs: uses: actions-rs/cargo@v1 with: command: fetch - - name: install LLVM on Windows + - name: Install LLVM on Windows if: matrix.os == 'windows-latest' run: choco install llvm -y + - name: Skip network tests on Ubuntu + # Ubuntu runners don't have network or DNS configured during test steps + if: matrix.os == 'ubuntu-latest' + run: echo "ZEBRA_SKIP_NETWORK_TESTS=1" >> $GITHUB_ENV - name: Run tests env: RUST_BACKTRACE: full @@ -67,7 +71,7 @@ jobs: with: toolchain: stable override: true - - name: install LLVM on Windows + - name: Install LLVM on Windows if: matrix.os == 'windows-latest' run: choco install llvm -y - name: cargo fetch diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 7a695ed90d5..c83db04cae5 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -20,6 +20,9 @@ jobs: with: toolchain: stable override: true + - name: Skip network tests on Ubuntu + # Ubuntu runners don't have network or DNS configured during test steps + run: echo "ZEBRA_SKIP_NETWORK_TESTS=1" >> $GITHUB_ENV - name: Run cargo-tarpaulin uses: actions-rs/tarpaulin@v0.1 with: From 760db2d8a4e2c1cb6d0836d093a72e35ab04f50c Mon Sep 17 00:00:00 2001 From: teor Date: Tue, 20 Oct 2020 19:51:47 +1000 Subject: [PATCH 3/5] Remove a redundant condition in expect_stdout When the loop exits, either the process has stopped running, or the deadline has passed. If the process is still running, we want to kill it. --- zebra-test/src/command.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zebra-test/src/command.rs b/zebra-test/src/command.rs index b6b3255e542..0323e454304 100644 --- a/zebra-test/src/command.rs +++ b/zebra-test/src/command.rs @@ -231,7 +231,7 @@ impl TestChild { } } - if self.past_deadline() && self.is_running() { + if self.is_running() { // If the process exits between is_running and kill, we will see // spurious errors here. If that happens, ignore "no such process" // errors from kill. From bf6d9ac0230e3ee71ba515dc7e37475c9ed1933e Mon Sep 17 00:00:00 2001 From: teor Date: Tue, 20 Oct 2020 19:45:27 +1000 Subject: [PATCH 4/5] Refactor sync test to be more flexible And add documentation --- zebrad/tests/acceptance.rs | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/zebrad/tests/acceptance.rs b/zebrad/tests/acceptance.rs index f940eb66090..61f17e7af1b 100644 --- a/zebrad/tests/acceptance.rs +++ b/zebrad/tests/acceptance.rs @@ -457,23 +457,34 @@ fn valid_generated_config(command: &str, expected_output: &str) -> Result<()> { /// Test if `zebrad` can sync the first checkpoint on mainnet. /// -/// If your test environment does not have network access, skip -/// this test by setting the `ZEBRA_SKIP_NETWORK_TESTS` env var. +/// The first checkpoint contains a single genesis block. #[test] fn sync_one_checkpoint_mainnet() -> Result<()> { - sync_one_checkpoint(Mainnet) + sync_until( + "verified checkpoint range", + Mainnet, + Duration::from_secs(20), + ) } /// Test if `zebrad` can sync the first checkpoint on testnet. /// -/// If your test environment does not have network access, skip -/// this test by setting the `ZEBRA_SKIP_NETWORK_TESTS` env var. +/// The first checkpoint contains a single genesis block. #[test] fn sync_one_checkpoint_testnet() -> Result<()> { - sync_one_checkpoint(Testnet) + sync_until( + "verified checkpoint range", + Testnet, + Duration::from_secs(20), + ) } -fn sync_one_checkpoint(network: Network) -> Result<()> { +/// Sync `network` until `zebrad` outputs `regex`. +/// Returns an error if `timeout` elapses before `regex` is output. +/// +/// If your test environment does not have network access, skip +/// this test by setting the `ZEBRA_SKIP_NETWORK_TESTS` env var. +fn sync_until(regex: &str, network: Network, timeout: Duration) -> Result<()> { zebra_test::init(); if env::var_os("ZEBRA_SKIP_NETWORK_TESTS").is_some() { @@ -483,6 +494,7 @@ fn sync_one_checkpoint(network: Network) -> Result<()> { return Ok(()); } + // Use a persistent state, so we can handle large syncs let mut config = persistent_test_config()?; // TODO: add a convenience method? config.network.network = network; @@ -490,11 +502,11 @@ fn sync_one_checkpoint(network: Network) -> Result<()> { let mut child = testdir()? .with_config(config)? .spawn_child(&["start"])? - .with_timeout(Duration::from_secs(20)); + .with_timeout(timeout); // TODO: is there a way to check for testnet or mainnet here? // For example: "network=Mainnet" or "network=Testnet" - child.expect_stdout("verified checkpoint range")?; + child.expect_stdout(regex)?; child.kill()?; Ok(()) From eab009bae2e9b904637df0fd69cc24f7a3829053 Mon Sep 17 00:00:00 2001 From: teor Date: Wed, 21 Oct 2020 08:55:47 +1000 Subject: [PATCH 5/5] Disable sync tests on Windows CI --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 80d3b5171fe..3dc3d6875ab 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,9 +25,10 @@ jobs: - name: Install LLVM on Windows if: matrix.os == 'windows-latest' run: choco install llvm -y - - name: Skip network tests on Ubuntu + - name: Skip network tests on Ubuntu and Windows # Ubuntu runners don't have network or DNS configured during test steps - if: matrix.os == 'ubuntu-latest' + # Windows runners have an unreliable network + if: matrix.os == 'ubuntu-latest' || matrix.os == 'windows-latest' run: echo "ZEBRA_SKIP_NETWORK_TESTS=1" >> $GITHUB_ENV - name: Run tests env: