wait up to a second for it to sync

This commit is contained in:
Bryan Stitt 2023-06-24 21:51:58 -07:00
parent e7baeb1ba4
commit 83123f5cdd
2 changed files with 23 additions and 11 deletions

@ -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

@ -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<ArcBlock>>("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<ArcBlock>>("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<ArcBlock>>("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;
}