Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Apr 25, 2024
1 parent 663b98b commit 4251ff1
Showing 1 changed file with 47 additions and 14 deletions.
61 changes: 47 additions & 14 deletions nano/core_test/stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,56 @@
#include <ostream>

// Test stat counting at both type and detail levels
TEST (stats, stat_counting)
TEST (stats, counters)
{
nano::test::system system (1);
auto & node1 (*system.nodes[0]);
nano::test::system system;
auto & node = *system.add_node ();

node1.stats.add (nano::stat::type::ledger, nano::stat::detail::test, nano::stat::dir::in, 1);
node1.stats.add (nano::stat::type::ledger, nano::stat::detail::test, nano::stat::dir::in, 5);
node1.stats.inc (nano::stat::type::ledger, nano::stat::detail::test, nano::stat::dir::in);
node1.stats.inc (nano::stat::type::ledger, nano::stat::detail::send, nano::stat::dir::in);
node1.stats.inc (nano::stat::type::ledger, nano::stat::detail::send, nano::stat::dir::in);
node1.stats.inc (nano::stat::type::ledger, nano::stat::detail::receive, nano::stat::dir::in);
node.stats.add (nano::stat::type::ledger, nano::stat::detail::test, nano::stat::dir::in, 1);
node.stats.add (nano::stat::type::ledger, nano::stat::detail::test, nano::stat::dir::in, 5);
node.stats.inc (nano::stat::type::ledger, nano::stat::detail::test, nano::stat::dir::in);
node.stats.inc (nano::stat::type::ledger, nano::stat::detail::send, nano::stat::dir::in);
node.stats.inc (nano::stat::type::ledger, nano::stat::detail::send, nano::stat::dir::in);
node.stats.inc (nano::stat::type::ledger, nano::stat::detail::receive, nano::stat::dir::in);

ASSERT_EQ (10, node1.stats.count (nano::stat::type::ledger, nano::stat::dir::in));
ASSERT_EQ (2, node1.stats.count (nano::stat::type::ledger, nano::stat::detail::send, nano::stat::dir::in));
ASSERT_EQ (1, node1.stats.count (nano::stat::type::ledger, nano::stat::detail::receive, nano::stat::dir::in));
ASSERT_EQ (10, node.stats.count (nano::stat::type::ledger, nano::stat::dir::in));
ASSERT_EQ (2, node.stats.count (nano::stat::type::ledger, nano::stat::detail::send, nano::stat::dir::in));
ASSERT_EQ (1, node.stats.count (nano::stat::type::ledger, nano::stat::detail::receive, nano::stat::dir::in));

node1.stats.add (nano::stat::type::ledger, nano::stat::detail::test, nano::stat::dir::in, 0);
node.stats.add (nano::stat::type::ledger, nano::stat::detail::test, nano::stat::dir::in, 0);

ASSERT_EQ (10, node1.stats.count (nano::stat::type::ledger, nano::stat::dir::in));
ASSERT_EQ (10, node.stats.count (nano::stat::type::ledger, nano::stat::dir::in));
}

TEST (stats, samples)
{
nano::test::system system;
auto & node = *system.add_node ();

node.stats.sample (nano::stat::sample::active_election_duration, { 1, 10 }, 5);
node.stats.sample (nano::stat::sample::active_election_duration, { 1, 10 }, 5);
node.stats.sample (nano::stat::sample::active_election_duration, { 1, 10 }, 11);
node.stats.sample (nano::stat::sample::active_election_duration, { 1, 10 }, 37);

node.stats.sample (nano::stat::sample::bootstrap_tag_duration, { 1, 10 }, 2137);

auto samples1 = node.stats.samples (nano::stat::sample::active_election_duration);
ASSERT_EQ (4, samples1.size ());
ASSERT_EQ (5, samples1[0]);
ASSERT_EQ (5, samples1[1]);
ASSERT_EQ (11, samples1[2]);
ASSERT_EQ (37, samples1[3]);

auto samples2 = node.stats.samples (nano::stat::sample::active_election_duration);
ASSERT_EQ (0, samples2.size ());

node.stats.sample (nano::stat::sample::active_election_duration, { 1, 10 }, 3);

auto samples3 = node.stats.samples (nano::stat::sample::active_election_duration);
ASSERT_EQ (1, samples3.size ());
ASSERT_EQ (3, samples3[0]);

auto samples4 = node.stats.samples (nano::stat::sample::bootstrap_tag_duration);
ASSERT_EQ (1, samples4.size ());
ASSERT_EQ (2137, samples4[0]);
}

0 comments on commit 4251ff1

Please sign in to comment.