From 4251ff1b6a131768e3ab1172ef3816f88c8de44d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Thu, 25 Apr 2024 15:50:55 +0200 Subject: [PATCH] More tests --- nano/core_test/stats.cpp | 61 +++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 14 deletions(-) diff --git a/nano/core_test/stats.cpp b/nano/core_test/stats.cpp index b099300c20..010c46d609 100644 --- a/nano/core_test/stats.cpp +++ b/nano/core_test/stats.cpp @@ -6,23 +6,56 @@ #include // 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]); } \ No newline at end of file