mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-06-26 08:59:45 +00:00
refactor: drastically shorten (480s to 160s) the test time by adding block wait helper
This commit is contained in:
parent
0db82d2344
commit
ea13ef10d8
@ -6,7 +6,6 @@
|
||||
|
||||
use anyhow::Result;
|
||||
use indexer_ffi::api::types::FfiOption;
|
||||
use integration_tests::L2_TO_L1_TIMEOUT;
|
||||
use log::info;
|
||||
|
||||
#[path = "indexer_ffi_helpers/mod.rs"]
|
||||
@ -18,17 +17,11 @@ fn indexer_ffi_block_batching() -> Result<()> {
|
||||
// duration of the test; the indexer was started on that runtime.
|
||||
let (_ctx, indexer_ffi, _indexer_dir) = indexer_ffi_helpers::setup()?;
|
||||
|
||||
// WAIT
|
||||
// WAIT: poll until the indexer has finalized at least two blocks (so the
|
||||
// chain-consistency check below verifies at least one block link), returning
|
||||
// early instead of sleeping for the full timeout.
|
||||
info!("Waiting for indexer to parse blocks");
|
||||
std::thread::sleep(L2_TO_L1_TIMEOUT);
|
||||
|
||||
let last_block_indexer_ffi_res =
|
||||
unsafe { indexer_ffi_helpers::query_last_block(&raw const indexer_ffi) };
|
||||
|
||||
assert!(last_block_indexer_ffi_res.error.is_ok());
|
||||
assert!(last_block_indexer_ffi_res.is_some);
|
||||
|
||||
let last_block_indexer = last_block_indexer_ffi_res.block_id;
|
||||
let last_block_indexer = indexer_ffi_helpers::wait_for_indexer_ffi_block(&indexer_ffi, 2)?;
|
||||
|
||||
info!("Last block on indexer FFI now is {last_block_indexer}");
|
||||
|
||||
|
||||
@ -84,3 +84,28 @@ pub fn setup() -> Result<(BlockingTestContext, IndexerServiceFFI, TempDir)> {
|
||||
let (indexer_ffi, indexer_dir) = setup_indexer_ffi(&runtime, ctx.ctx().bedrock_addr())?;
|
||||
Ok((ctx, indexer_ffi, indexer_dir))
|
||||
}
|
||||
|
||||
/// Poll the indexer FFI until its last finalized block id reaches `min_block_id`
|
||||
/// or until [`integration_tests::L2_TO_L1_TIMEOUT`] elapses.
|
||||
///
|
||||
/// This avoids blindly sleeping for the full timeout: the indexer typically
|
||||
/// catches up in a fraction of that time, so we return as soon as it does and
|
||||
/// only use the timeout as a ceiling. Returns the last observed block id.
|
||||
pub fn wait_for_indexer_ffi_block(indexer: &IndexerServiceFFI, min_block_id: u64) -> Result<u64> {
|
||||
let start = std::time::Instant::now();
|
||||
loop {
|
||||
// SAFETY: `indexer` is a valid reference for the duration of the call.
|
||||
let res = unsafe { query_last_block(std::ptr::from_ref(indexer)) };
|
||||
if res.error.is_ok() && res.is_some && res.block_id >= min_block_id {
|
||||
return Ok(res.block_id);
|
||||
}
|
||||
if start.elapsed() >= integration_tests::L2_TO_L1_TIMEOUT {
|
||||
anyhow::bail!(
|
||||
"Indexer FFI did not reach block {min_block_id} within {:?}. Last observed block id: {}",
|
||||
integration_tests::L2_TO_L1_TIMEOUT,
|
||||
res.block_id
|
||||
);
|
||||
}
|
||||
std::thread::sleep(std::time::Duration::from_secs(2));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
#![expect(
|
||||
clippy::tests_outside_test_module,
|
||||
clippy::undocumented_unsafe_blocks,
|
||||
reason = "We don't care about these in tests"
|
||||
)]
|
||||
|
||||
use anyhow::Result;
|
||||
use integration_tests::L2_TO_L1_TIMEOUT;
|
||||
use log::info;
|
||||
|
||||
#[path = "indexer_ffi_helpers/mod.rs"]
|
||||
@ -17,16 +15,10 @@ fn indexer_test_run_ffi() -> Result<()> {
|
||||
// duration of the test; the indexer was started on that runtime.
|
||||
let (_ctx, indexer_ffi, _indexer_dir) = indexer_ffi_helpers::setup()?;
|
||||
|
||||
// RUN OBSERVATION
|
||||
std::thread::sleep(L2_TO_L1_TIMEOUT);
|
||||
|
||||
let last_block_indexer_ffi_res =
|
||||
unsafe { indexer_ffi_helpers::query_last_block(&raw const indexer_ffi) };
|
||||
|
||||
assert!(last_block_indexer_ffi_res.error.is_ok());
|
||||
assert!(last_block_indexer_ffi_res.is_some);
|
||||
|
||||
let last_block_indexer_ffi = last_block_indexer_ffi_res.block_id;
|
||||
// RUN OBSERVATION: poll until the indexer has finalized at least one block,
|
||||
// returning early instead of sleeping for the full timeout.
|
||||
let last_block_indexer_ffi =
|
||||
indexer_ffi_helpers::wait_for_indexer_ffi_block(&indexer_ffi, 1)?;
|
||||
|
||||
info!("Last block on indexer FFI now is {last_block_indexer_ffi}");
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user