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

test(lightwalletd): wait for successful block ingestion in integration tests #3824

Merged
merged 3 commits into from
Mar 12, 2022
Merged
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
35 changes: 26 additions & 9 deletions zebrad/tests/acceptance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ use zebrad::{
/// metrics or tracing test failures in Windows CI.
const LAUNCH_DELAY: Duration = Duration::from_secs(15);

/// The amount of time we wait after launching `lightwalletd`,
/// and between expected `lightwalletd` log messages.
const LIGHTWALLETD_DELAY: Duration = Duration::from_secs(60);

/// The amount of time we wait between launching two
/// conflicting nodes.
const BETWEEN_NODES_DELAY: Duration = Duration::from_secs(2);
Expand Down Expand Up @@ -1669,36 +1673,49 @@ fn lightwalletd_integration() -> Result<()> {
// Launch the lightwalletd process
let result = ldir.spawn_lightwalletd_child(&[]);
let (lightwalletd, zebrad) = zebrad.kill_on_error(result)?;
let mut lightwalletd = lightwalletd.with_timeout(LAUNCH_DELAY);
let mut lightwalletd = lightwalletd.with_timeout(LIGHTWALLETD_DELAY);

// Wait until `lightwalletd` has launched
let result = lightwalletd.expect_stdout_line_matches("Starting gRPC server");
let (_, zebrad) = zebrad.kill_on_error(result)?;

// Check that `lightwalletd` is calling the expected Zebra RPCs
//
// TODO: add extra checks when we add new Zebra RPCs

// get_blockchain_info
// getblockchaininfo
let result = lightwalletd.expect_stdout_line_matches("Got sapling height");
let (_, zebrad) = zebrad.kill_on_error(result)?;

let result = lightwalletd.expect_stdout_line_matches("Found 0 blocks in cache");
let (_, zebrad) = zebrad.kill_on_error(result)?;

// Check that `lightwalletd` got to the first unimplemented Zebra RPC
// getblock with block 1 in Zebra's state
//
// TODO: update the missing method name when we add a new Zebra RPC

// zcash/lightwalletd calls getbestblockhash here, but
// adityapk00/lightwalletd calls getblock
let result =
lightwalletd.expect_stdout_line_matches("Block hash changed, clearing mempool clients");
//
// Until block 1 has been downloaded, lightwalletd will log Zebra's RPC error:
// "error requesting block: 0: Block not found"
// But we can't check for that, because Zebra might download genesis before lightwalletd asks.
// We also get a similar log when lightwalletd reaches the end of Zebra's cache.
//
// After the first getblock call, lightwalletd will log:
// "Block hash changed, clearing mempool clients"
// But we can't check for that, because it can come before or after the Ingestor log.
let result = lightwalletd.expect_stdout_line_matches("Ingestor adding block to cache");
let (_, zebrad) = zebrad.kill_on_error(result)?;

// (next RPC)
//
// TODO: add extra checks when we add new Zebra RPCs

// Unimplemented getrawmempool (repeated, in a separate lightwalletd thread)
//
// zcash/lightwalletd exits with a fatal error here.
// adityapk00/lightwalletd keeps trying the mempool,
// but it sometimes skips the "Method not found" log line.
//
// If a refresh is pending, we can get "Mempool refresh error" before the Ingestor log,
// and "Another refresh is in progress" after it.
let result =
lightwalletd.expect_stdout_line_matches("(Mempool refresh error: -32601: Method not found)|(Another refresh in progress, returning)");
let (_, zebrad) = zebrad.kill_on_error(result)?;
Expand Down