Replace block_processor::flush in unit tests with an equivalent ASSERT_TIMELY for the expected behaviour for the test.

This commit is contained in:
Colin LeMahieu 2024-01-26 16:08:29 +00:00
commit b187757f5b
No known key found for this signature in database
GPG key ID: 43708520C8DFB938
6 changed files with 21 additions and 22 deletions

View file

@ -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<nano::block_hash, std::shared_ptr<nano::block>> 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

View file

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

View file

@ -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 ()));

View file

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

View file

@ -355,8 +355,7 @@ TEST (node, receive_gap)
nano::publish message{ nano::dev::network_params.network, block };
auto channel1 = std::make_shared<nano::transport::fake::channel> (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 ());

View file

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