Skip to content

Commit

Permalink
Improve unit test telemetry.basic (#4589)
Browse files Browse the repository at this point in the history
Reduce the chances of failure. The test could easily fail if a telemetry
update happened at the wrong time. This change reduces the chance of
that happening.
  • Loading branch information
dsiganos authored Apr 30, 2024
1 parent 961cae3 commit 53294c9
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions nano/core_test/telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,17 +299,23 @@ TEST (telemetry, basic)
// Check the metrics are correct
ASSERT_TRUE (nano::test::compare_telemetry (*telemetry_data, *node_server));

// Call again straight away. It should use the cache
// Call again straight away
auto telemetry_data_2 = node_client->telemetry.get_telemetry (channel->get_endpoint ());
ASSERT_TRUE (telemetry_data_2);
ASSERT_EQ (*telemetry_data, *telemetry_data_2);

// Call again straight away
auto telemetry_data_3 = node_client->telemetry.get_telemetry (channel->get_endpoint ());
ASSERT_TRUE (telemetry_data_3);

// we expect at least one consecutive repeat of telemetry
ASSERT_TRUE (*telemetry_data == telemetry_data_2 || telemetry_data_2 == telemetry_data_3);

// Wait the cache period and check cache is not used
WAIT (3s);

std::optional<nano::telemetry_data> telemetry_data_3;
ASSERT_TIMELY (5s, telemetry_data_3 = node_client->telemetry.get_telemetry (channel->get_endpoint ()));
ASSERT_NE (*telemetry_data, *telemetry_data_3);
std::optional<nano::telemetry_data> telemetry_data_4;
ASSERT_TIMELY (5s, telemetry_data_4 = node_client->telemetry.get_telemetry (channel->get_endpoint ()));
ASSERT_NE (*telemetry_data, *telemetry_data_4);
}

TEST (telemetry, invalid_endpoint)
Expand Down

0 comments on commit 53294c9

Please sign in to comment.