Skip to content

Commit

Permalink
add testcase for election_scheduler.transition_optimistic_to_priority
Browse files Browse the repository at this point in the history
  • Loading branch information
gr0vity committed Dec 1, 2024
1 parent b3aa270 commit 42c81d5
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions nano/core_test/election_scheduler.cpp
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
#include <nano/node/scheduler/component.hpp>
#include <nano/node/scheduler/priority.hpp>
#include <nano/secure/ledger.hpp>
#include <nano/test_common/chains.hpp>
#include <nano/test_common/system.hpp>
#include <nano/test_common/testutil.hpp>

@@ -157,6 +158,43 @@ TEST (election_scheduler, activate_one_flush)
ASSERT_TIMELY (5s, node.active.election (send1->qualified_root ()));
}


TEST (election_scheduler, transition_optimistic_to_priority)
{
nano::test::system system;
nano::node_config config = system.default_config ();
config.optimistic_scheduler.gap_threshold = 1;
auto & node = *system.add_node (config);

// Create a chain of blocks
const int howmany_blocks = 2;
auto chains = nano::test::setup_chains (system, node, /* single chain */ 1, howmany_blocks, nano::dev::genesis_key, /* do not confirm */ false);
auto & [account, blocks] = chains.front ();

// Priority election is created for the first block in chain
ASSERT_TIMELY (1s, node.active.size () == 1);

// Wait for the optimistic election to start
auto const & block = blocks.back ();
ASSERT_TIMELY (5s, node.vote_router.active (block->hash ()));
auto election = node.active.election (block->qualified_root ());
ASSERT_EQ (election->behavior (), nano::election_behavior::optimistic);
ASSERT_EQ (node.active.size (), 2);

// Confirm block prior to the optimitic election
nano::test::confirm (node.ledger, blocks.at (howmany_blocks - 1));

// Now activate a priority election for the same block
auto secure_transaction (node.ledger.tx_begin_read ());
node.scheduler.priority.activate (secure_transaction, nano::dev::genesis_key.pub);

// Verify the election was upgraded to priority
ASSERT_TIMELY (5s, election->behavior () == nano::election_behavior::priority);

// Verify the election is still active and properly transitioned
ASSERT_TRUE (node.active.active (*block));
}

/**
* Tests that the election scheduler and the active transactions container (AEC)
* work in sync with regards to the node configuration value "active_elections.size".

0 comments on commit 42c81d5

Please sign in to comment.