Skip to content

Commit

Permalink
Improve test_accept_not_a_better_block wait chain_service finished be…
Browse files Browse the repository at this point in the history
…fore exit

Signed-off-by: Eval EXEC <[email protected]>
  • Loading branch information
eval-exec committed Aug 2, 2024
1 parent b31c07d commit dc5dfb8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
15 changes: 15 additions & 0 deletions sync/src/relayer/tests/compact_block_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,21 @@ fn test_accept_not_a_better_block() {
peer_index,
);
assert_eq!(compact_block_process.execute(), Status::ok());

// wait chain_service processed the compact block, check block hash in snapshot
{
let now = std::time::Instant::now();
loop {
std::thread::sleep(std::time::Duration::from_millis(100));
if now.elapsed().as_secs() > 5 {
panic!("wait chain_service processed the compact block timeout");
}
let snapshot = relayer.shared.shared().snapshot();
if snapshot.get_block(&uncle_block.header().hash()).is_some() {
break;
}
}
}
}

#[test]
Expand Down
6 changes: 3 additions & 3 deletions sync/src/tests/sync_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ fn test_sync_relay_collaboration() {
{
let now = std::time::Instant::now();
while sync_shared.active_chain().tip_number() != new_block.number() {
std::thread::sleep(std::time::Duration::from_millis(10));
std::thread::sleep(std::time::Duration::from_millis(100));
if now.elapsed().as_secs() > 10 {
panic!("wait 10 seconds, but not sync yet.");
}
Expand Down Expand Up @@ -442,7 +442,7 @@ fn test_sync_relay_collaboration2() {
{
let now = std::time::Instant::now();
while sync_shared.active_chain().tip_number() != new_block.number() {
std::thread::sleep(std::time::Duration::from_millis(10));
std::thread::sleep(std::time::Duration::from_millis(100));
if now.elapsed().as_secs() > 10 {
panic!("wait 10 seconds, but not sync yet.");
}
Expand All @@ -465,7 +465,7 @@ fn test_sync_relay_collaboration2() {
{
let now = std::time::Instant::now();
while sync_shared.active_chain().tip_number() != new_block.number() {
std::thread::sleep(std::time::Duration::from_millis(10));
std::thread::sleep(std::time::Duration::from_millis(100));
if now.elapsed().as_secs() > 10 {
panic!("wait 10 seconds, but not sync yet.");
}
Expand Down
4 changes: 4 additions & 0 deletions sync/src/tests/synchronizer/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ fn start_chain(consensus: Option<Consensus>) -> (ChainController, Shared, Synchr

let chain_controller = start_chain_services(pack.take_chain_services_builder());

while chain_controller.is_verifying_unverified_blocks_on_startup() {
std::thread::sleep(std::time::Duration::from_millis(10));
}

let sync_shared = Arc::new(SyncShared::new(
shared.clone(),
Default::default(),
Expand Down

0 comments on commit dc5dfb8

Please sign in to comment.