Skip to content

Commit

Permalink
Renaming test_insert to nano::test::active_transactions_insert_null a…
Browse files Browse the repository at this point in the history
…nd placing in testutil.hpp
  • Loading branch information
clemahieu committed Sep 3, 2023
1 parent 3055266 commit 9c99f53
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 27 deletions.
36 changes: 16 additions & 20 deletions nano/core_test/scheduler_buckets.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <nano/node/scheduler/buckets.hpp>
#include <nano/secure/common.hpp>
#include <nano/test_common/testutil.hpp>

#include <gtest/gtest.h>

Expand Down Expand Up @@ -106,42 +107,37 @@ std::shared_ptr<nano::state_block> & block3 ()
return result;
}

namespace
{
auto test_insert = [] (std::shared_ptr<nano::block> const & block, nano::election_behavior behavior) { return nano::election_insertion_result{}; };
}

TEST (buckets, construction)
{
nano::scheduler::buckets buckets{ test_insert };
nano::scheduler::buckets buckets{ nano::test::active_transactions_insert_null };
ASSERT_EQ (0, buckets.size ());
ASSERT_TRUE (buckets.empty ());
ASSERT_EQ (62, buckets.bucket_count ());
}

TEST (buckets, index_min)
{
nano::scheduler::buckets buckets{ test_insert };
nano::scheduler::buckets buckets{ nano::test::active_transactions_insert_null };
ASSERT_EQ (0, buckets.index (std::numeric_limits<nano::uint128_t>::min ()));
}

TEST (buckets, index_max)
{
nano::scheduler::buckets buckets{ test_insert };
nano::scheduler::buckets buckets{ nano::test::active_transactions_insert_null };
ASSERT_EQ (buckets.bucket_count () - 1, buckets.index (std::numeric_limits<nano::uint128_t>::max ()));
}

TEST (buckets, insert_Gxrb)
{
nano::scheduler::buckets buckets{ test_insert };
nano::scheduler::buckets buckets{ nano::test::active_transactions_insert_null };
buckets.push (1000, block0 (), nano::Gxrb_ratio);
ASSERT_EQ (1, buckets.size ());
ASSERT_EQ (1, buckets.bucket_size (48));
}

TEST (buckets, insert_Mxrb)
{
nano::scheduler::buckets buckets{ test_insert };
nano::scheduler::buckets buckets{ nano::test::active_transactions_insert_null };
buckets.push (1000, block1 (), nano::Mxrb_ratio);
ASSERT_EQ (1, buckets.size ());
ASSERT_EQ (1, buckets.bucket_size (13));
Expand All @@ -150,7 +146,7 @@ TEST (buckets, insert_Mxrb)
// Test two blocks with the same priority
TEST (buckets, insert_same_priority)
{
nano::scheduler::buckets buckets{ test_insert };
nano::scheduler::buckets buckets{ nano::test::active_transactions_insert_null };
buckets.push (1000, block0 (), nano::Gxrb_ratio);
buckets.push (1000, block2 (), nano::Gxrb_ratio);
ASSERT_EQ (2, buckets.size ());
Expand All @@ -160,7 +156,7 @@ TEST (buckets, insert_same_priority)
// Test the same block inserted multiple times
TEST (buckets, insert_duplicate)
{
nano::scheduler::buckets buckets{ test_insert };
nano::scheduler::buckets buckets{ nano::test::active_transactions_insert_null };
buckets.push (1000, block0 (), nano::Gxrb_ratio);
buckets.push (1000, block0 (), nano::Gxrb_ratio);
ASSERT_EQ (1, buckets.size ());
Expand All @@ -169,7 +165,7 @@ TEST (buckets, insert_duplicate)

TEST (buckets, insert_older)
{
nano::scheduler::buckets buckets{ test_insert };
nano::scheduler::buckets buckets{ nano::test::active_transactions_insert_null };
buckets.push (1000, block0 (), nano::Gxrb_ratio);
buckets.push (1100, block2 (), nano::Gxrb_ratio);
ASSERT_EQ (block0 (), buckets.top ().first);
Expand All @@ -180,7 +176,7 @@ TEST (buckets, insert_older)

TEST (buckets, pop)
{
nano::scheduler::buckets buckets{ test_insert };
nano::scheduler::buckets buckets{ nano::test::active_transactions_insert_null };
ASSERT_TRUE (buckets.empty ());
buckets.push (1000, block0 (), nano::Gxrb_ratio);
ASSERT_FALSE (buckets.empty ());
Expand All @@ -190,14 +186,14 @@ TEST (buckets, pop)

TEST (buckets, top_one)
{
nano::scheduler::buckets buckets{ test_insert };
nano::scheduler::buckets buckets{ nano::test::active_transactions_insert_null };
buckets.push (1000, block0 (), nano::Gxrb_ratio);
ASSERT_EQ (block0 (), buckets.top ().first);
}

TEST (buckets, top_two)
{
nano::scheduler::buckets buckets{ test_insert };
nano::scheduler::buckets buckets{ nano::test::active_transactions_insert_null };
buckets.push (1000, block0 (), nano::Gxrb_ratio);
buckets.push (1, block1 (), nano::Mxrb_ratio);
ASSERT_EQ (block0 (), buckets.top ().first);
Expand All @@ -209,7 +205,7 @@ TEST (buckets, top_two)

TEST (buckets, top_round_robin)
{
nano::scheduler::buckets buckets{ test_insert };
nano::scheduler::buckets buckets{ nano::test::active_transactions_insert_null };
buckets.push (1000, blockzero (), 0);
ASSERT_EQ (blockzero (), buckets.top ().first);
buckets.push (1000, block0 (), nano::Gxrb_ratio);
Expand All @@ -227,7 +223,7 @@ TEST (buckets, top_round_robin)

TEST (buckets, trim_normal)
{
nano::scheduler::buckets buckets{ test_insert, 1 };
nano::scheduler::buckets buckets{ nano::test::active_transactions_insert_null, 1 };
buckets.push (1000, block0 (), nano::Gxrb_ratio);
buckets.push (1100, block2 (), nano::Gxrb_ratio);
ASSERT_EQ (1, buckets.size ());
Expand All @@ -236,7 +232,7 @@ TEST (buckets, trim_normal)

TEST (buckets, trim_reverse)
{
nano::scheduler::buckets buckets{ test_insert, 1 };
nano::scheduler::buckets buckets{ nano::test::active_transactions_insert_null, 1 };
buckets.push (1100, block2 (), nano::Gxrb_ratio);
buckets.push (1000, block0 (), nano::Gxrb_ratio);
ASSERT_EQ (1, buckets.size ());
Expand All @@ -245,7 +241,7 @@ TEST (buckets, trim_reverse)

TEST (buckets, trim_even)
{
nano::scheduler::buckets buckets{ test_insert, 2 };
nano::scheduler::buckets buckets{ nano::test::active_transactions_insert_null, 2 };
buckets.push (1000, block0 (), nano::Gxrb_ratio);
buckets.push (1100, block2 (), nano::Gxrb_ratio);
ASSERT_EQ (1, buckets.size ());
Expand Down
9 changes: 2 additions & 7 deletions nano/core_test/scheduler_limiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,16 @@

#include <gtest/gtest.h>

namespace
{
auto test_insert = [] (std::shared_ptr<nano::block> const & block, nano::election_behavior behavior) { return nano::election_insertion_result{}; };
}

TEST (scheduler_limiter, construction)
{
auto occupancy = std::make_shared<nano::scheduler::limiter> (test_insert, 0, nano::election_behavior::normal);
auto occupancy = std::make_shared<nano::scheduler::limiter> (nano::test::active_transactions_insert_null, 0, nano::election_behavior::normal);
ASSERT_EQ (0, occupancy->limit ());
ASSERT_FALSE (occupancy->available ());
}

TEST (scheduler_limiter, limit)
{
auto occupancy = std::make_shared<nano::scheduler::limiter> (test_insert, 1, nano::election_behavior::normal);
auto occupancy = std::make_shared<nano::scheduler::limiter> (nano::test::active_transactions_insert_null, 1, nano::election_behavior::normal);
ASSERT_EQ (1, occupancy->limit ());
ASSERT_TRUE (occupancy->available ());
}
Expand Down
3 changes: 3 additions & 0 deletions nano/test_common/testutil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <nano/lib/errors.hpp>
#include <nano/lib/locks.hpp>
#include <nano/lib/timer.hpp>
#include <nano/node/election_insertion_result.hpp>
#include <nano/node/transport/channel.hpp>
#include <nano/node/transport/transport.hpp>

Expand Down Expand Up @@ -131,6 +132,7 @@ class network_params;
class vote;
class block;
class election;
enum class election_behavior;

extern nano::uint128_t const & genesis_amount;

Expand Down Expand Up @@ -428,5 +430,6 @@ namespace test
* NOTE: Each election is given 5 seconds to complete, if it does not complete in 5 seconds, it will assert.
*/
void start_elections (nano::test::system &, nano::node &, std::vector<std::shared_ptr<nano::block>> const &, bool const forced_a = false);
auto active_transactions_insert_null = [] (std::shared_ptr<nano::block> const & block, nano::election_behavior behavior) { return nano::election_insertion_result{}; };
}
}

0 comments on commit 9c99f53

Please sign in to comment.