From 83123f5cdd60f09c29633708fd77191e401d33c4 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Sat, 24 Jun 2023 21:51:58 -0700 Subject: [PATCH] wait up to a second for it to sync --- Dockerfile | 2 +- web3_proxy/src/bin/web3_proxy_cli/proxyd.rs | 32 ++++++++++++++------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 61d54a37..12a82136 100644 --- a/Dockerfile +++ b/Dockerfile @@ -56,7 +56,7 @@ ENV WEB3_PROXY_FEATURES "rdkafka-src,connectinfo" # test the application with cargo-nextest RUN --mount=type=cache,target=/usr/local/cargo/registry \ --mount=type=cache,target=/app/target \ - cargo nextest run --features "$WEB3_PROXY_FEATURES" --no-default-features + RUST_LOG=web3_proxy=trace,info cargo nextest run --features "$WEB3_PROXY_FEATURES" --no-default-features # build the application # using a "release" profile (which install does by default) is **very** important diff --git a/web3_proxy/src/bin/web3_proxy_cli/proxyd.rs b/web3_proxy/src/bin/web3_proxy_cli/proxyd.rs index 8a673c59..77baaca0 100644 --- a/web3_proxy/src/bin/web3_proxy_cli/proxyd.rs +++ b/web3_proxy/src/bin/web3_proxy_cli/proxyd.rs @@ -269,7 +269,7 @@ mod tests { }; use tokio::{ sync::broadcast::error::SendError, - task::{yield_now, JoinHandle}, + task::JoinHandle, time::{sleep, Instant}, }; use web3_proxy::{ @@ -424,9 +424,6 @@ mod tests { .await .unwrap(); - // TODO: local doesn't need this, but jenkins seems to - sleep(Duration::from_millis(10)).await; - // make sure the block advanced let anvil_result = anvil_provider .request::<_, Option>("eth_getBlockByNumber", ("latest", false)) @@ -438,13 +435,28 @@ mod tests { assert_eq!(first_block_num, second_block_num - 1); - let proxy_result = proxy_provider - .request::<_, Option>("eth_getBlockByNumber", ("latest", false)) - .await - .unwrap() - .unwrap(); + let mut proxy_result; + let start = Instant::now(); + loop { + if start.elapsed() > Duration::from_secs(1) { + panic!("took too long to sync!"); + } - assert_eq!(anvil_result, proxy_result); + proxy_result = proxy_provider + .request::<_, Option>("eth_getBlockByNumber", ("latest", false)) + .await + .unwrap(); + + if let Some(ref proxy_result) = proxy_result { + if proxy_result.number != Some(first_block_num) { + break; + } + } + + sleep(Duration::from_millis(10)).await; + } + + assert_eq!(anvil_result, proxy_result.unwrap()); x.wait().await; }