From b187757f5ba729d56e4941772e819f7d437703ff Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Fri, 26 Jan 2024 16:08:29 +0000 Subject: [PATCH] Replace block_processor::flush in unit tests with an equivalent ASSERT_TIMELY for the expected behaviour for the test. --- nano/core_test/active_transactions.cpp | 8 +++----- nano/core_test/confirmation_height.cpp | 6 ++++-- nano/core_test/gap_cache.cpp | 6 ++---- nano/core_test/network.cpp | 4 ++-- nano/core_test/node.cpp | 15 ++++++++------- nano/core_test/wallet.cpp | 4 ++-- 6 files changed, 21 insertions(+), 22 deletions(-) diff --git a/nano/core_test/active_transactions.cpp b/nano/core_test/active_transactions.cpp index dbbb32cf..910a518c 100644 --- a/nano/core_test/active_transactions.cpp +++ b/nano/core_test/active_transactions.cpp @@ -756,7 +756,7 @@ TEST (active_transactions, republish_winner) .build_shared (); node1.process_active (fork); - node1.block_processor.flush (); + ASSERT_TIMELY (5s, node1.active.active (fork->hash ())); auto election = node1.active.election (fork->qualified_root ()); ASSERT_NE (nullptr, election); auto vote = nano::test::make_final_vote (nano::dev::genesis_key, { fork }); @@ -974,12 +974,10 @@ TEST (active_transactions, fork_replacement_tally) node1.network.publish_filter.clear (); node2.network.flood_block (send_last); ASSERT_TIMELY (3s, node1.stats.count (nano::stat::type::message, nano::stat::detail::publish, nano::stat::dir::in) > 0); - node1.block_processor.flush (); - system.delay_ms (50ms); // Correct block without votes is ignored - auto blocks1 (election->blocks ()); - ASSERT_EQ (max_blocks, blocks1.size ()); + std::unordered_map> blocks1; + ASSERT_TIMELY_EQ (5s, max_blocks, (blocks1 = election->blocks (), blocks1.size ())); ASSERT_FALSE (blocks1.find (send_last->hash ()) != blocks1.end ()); // Process vote for correct block & replace existing lowest tally block diff --git a/nano/core_test/confirmation_height.cpp b/nano/core_test/confirmation_height.cpp index 15b6aa63..fb8b97c3 100644 --- a/nano/core_test/confirmation_height.cpp +++ b/nano/core_test/confirmation_height.cpp @@ -513,14 +513,16 @@ TEST (confirmation_height, gap_live) node->block_processor.add (send1); node->block_processor.add (send2); node->block_processor.add (send3); + // node->block_processor.add (open1); Witheld for test node->block_processor.add (receive1); - node->block_processor.flush (); + ASSERT_TIMELY (5s, nano::test::exists (*node, { send1, send2, send3 })); + ASSERT_TIMELY (5s, node->unchecked.exists ({ open1->hash (), receive1->hash () })); add_callback_stats (*node); // Receive 2 comes in on the live network, however the chain has not been finished so it gets added to unchecked node->process_active (receive2); - node->block_processor.flush (); + ASSERT_TIMELY (5s, node->unchecked.exists ({ receive1->hash (), receive2->hash () })); // Confirmation heights should not be updated { diff --git a/nano/core_test/gap_cache.cpp b/nano/core_test/gap_cache.cpp index 360e2ce2..561088db 100644 --- a/nano/core_test/gap_cache.cpp +++ b/nano/core_test/gap_cache.cpp @@ -157,11 +157,9 @@ TEST (gap_cache, two_dependencies) .build_shared (); ASSERT_EQ (0, node1.gap_cache.size ()); node1.block_processor.add (send2); - node1.block_processor.flush (); - ASSERT_EQ (1, node1.gap_cache.size ()); + ASSERT_TIMELY_EQ (5s, 1, node1.gap_cache.size ()); node1.block_processor.add (open); - node1.block_processor.flush (); - ASSERT_EQ (2, node1.gap_cache.size ()); + ASSERT_TIMELY_EQ (5s, 2, node1.gap_cache.size ()); node1.block_processor.add (send1); ASSERT_TIMELY_EQ (5s, node1.gap_cache.size (), 0); ASSERT_TIMELY (5s, node1.store.block.exists (node1.store.tx_begin_read (), send1->hash ())); diff --git a/nano/core_test/network.cpp b/nano/core_test/network.cpp index d2ab36df..acdc87d4 100644 --- a/nano/core_test/network.cpp +++ b/nano/core_test/network.cpp @@ -423,9 +423,9 @@ TEST (receivable_processor, send_with_receive) ASSERT_EQ (amount, node2.balance (nano::dev::genesis_key.pub)); ASSERT_EQ (0, node2.balance (key2.pub)); node1.process_active (block1); - node1.block_processor.flush (); + ASSERT_TIMELY (5s, nano::test::exists (node1, { block1 })); node2.process_active (block1); - node2.block_processor.flush (); + ASSERT_TIMELY (5s, nano::test::exists (node2, { block1 })); ASSERT_EQ (amount - node1.config.receive_minimum.number (), node1.balance (nano::dev::genesis_key.pub)); ASSERT_EQ (0, node1.balance (key2.pub)); ASSERT_EQ (amount - node1.config.receive_minimum.number (), node2.balance (nano::dev::genesis_key.pub)); diff --git a/nano/core_test/node.cpp b/nano/core_test/node.cpp index 5ba5b9e2..3f081f9f 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -355,8 +355,7 @@ TEST (node, receive_gap) nano::publish message{ nano::dev::network_params.network, block }; auto channel1 = std::make_shared (node1); node1.network.inbound (message, channel1); - node1.block_processor.flush (); - ASSERT_EQ (1, node1.gap_cache.size ()); + ASSERT_TIMELY_EQ (5s, 1, node1.gap_cache.size ()); } TEST (node, merge_peers) @@ -581,7 +580,7 @@ TEST (node, fork_publish) // Wait until the genesis rep activated & makes vote ASSERT_TIMELY_EQ (1s, election->votes ().size (), 2); node1.process_active (send2); - node1.block_processor.flush (); + ASSERT_TIMELY (5s, node1.active.active (*send2)); auto votes1 (election->votes ()); auto existing1 (votes1.find (nano::dev::genesis_key.pub)); ASSERT_NE (votes1.end (), existing1); @@ -676,10 +675,11 @@ TEST (node, fork_keep) ASSERT_TIMELY_EQ (5s, 1, node1.active.size ()); ASSERT_TIMELY_EQ (5s, 1, node2.active.size ()); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); + // Fill node with forked blocks node1.process_active (send2); - node1.block_processor.flush (); + ASSERT_TIMELY (5s, node1.active.active (*send2)); node2.process_active (send2); - node2.block_processor.flush (); + ASSERT_TIMELY (5s, node2.active.active (*send2)); auto election1 (node2.active.election (nano::qualified_root (nano::dev::genesis->hash (), nano::dev::genesis->hash ()))); ASSERT_NE (nullptr, election1); ASSERT_EQ (1, election1->votes ().size ()); @@ -729,10 +729,11 @@ TEST (node, fork_flip) ASSERT_TIMELY_EQ (5s, 1, node1.active.size ()); ASSERT_TIMELY_EQ (5s, 1, node2.active.size ()); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); + // Fill nodes with forked blocks node1.network.inbound (publish2, ignored_channel); - node1.block_processor.flush (); + ASSERT_TIMELY (5s, node1.active.active (*send2)); node2.network.inbound (publish1, ignored_channel); - node2.block_processor.flush (); + ASSERT_TIMELY (5s, node2.active.active (*send1)); auto election1 (node2.active.election (nano::qualified_root (nano::dev::genesis->hash (), nano::dev::genesis->hash ()))); ASSERT_NE (nullptr, election1); ASSERT_EQ (1, election1->votes ().size ()); diff --git a/nano/core_test/wallet.cpp b/nano/core_test/wallet.cpp index c2774952..625dbb79 100644 --- a/nano/core_test/wallet.cpp +++ b/nano/core_test/wallet.cpp @@ -946,7 +946,7 @@ TEST (wallet, change_seed) wallet->insert_adhoc (nano::dev::genesis_key.prv, false); auto block (wallet->send_action (nano::dev::genesis_key.pub, pub, 100)); ASSERT_NE (nullptr, block); - system.nodes[0]->block_processor.flush (); + ASSERT_TIMELY (5s, nano::test::exists (*system.nodes[0], { block })); { auto transaction (wallet->wallets.tx_begin_write ()); wallet->change_seed (transaction, seed1); @@ -980,7 +980,7 @@ TEST (wallet, deterministic_restore) wallet->insert_adhoc (nano::dev::genesis_key.prv, false); auto block (wallet->send_action (nano::dev::genesis_key.pub, pub, 100)); ASSERT_NE (nullptr, block); - system.nodes[0]->block_processor.flush (); + ASSERT_TIMELY (5s, nano::test::exists (*system.nodes[0], { block })); { auto transaction (wallet->wallets.tx_begin_write ()); wallet->deterministic_restore (transaction);