Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable zebrad sync tests by default #1179

Merged
merged 5 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ 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 and Windows
# Ubuntu runners don't have network or DNS configured during test steps
# 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:
RUST_BACKTRACE: full
Expand Down Expand Up @@ -67,7 +72,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
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
with:
Expand Down
2 changes: 1 addition & 1 deletion zebra-test/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ impl<T> TestChild<T> {
}
}

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.
Expand Down
32 changes: 21 additions & 11 deletions zebrad/tests/acceptance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,25 +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]
#[ignore]
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]
#[ignore]
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() {
Expand All @@ -485,18 +494,19 @@ 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;

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(())
Expand Down