Skip to content

Commit

Permalink
PEER CACHE TESTS
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Apr 17, 2024
1 parent 0625e3b commit cff0921
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions nano/core_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ add_executable(
processor_service.cpp
rep_crawler.cpp
receivable.cpp
peer_cache.cpp
peer_container.cpp
rep_weight_store.cpp
scheduler_buckets.cpp
Expand Down
48 changes: 48 additions & 0 deletions nano/core_test/peer_cache.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <nano/node/peer_cache.hpp>
#include <nano/test_common/system.hpp>
#include <nano/test_common/testutil.hpp>

#include <gtest/gtest.h>

TEST (peer_cache, store_live)
{
nano::test::system system;

auto & node1 = *system.add_node ();
auto & node2 = *system.add_node ();
auto & node3 = *system.add_node ();

ASSERT_TIMELY (5s, node1.peer_cache.exists (node2.network.endpoint ()));
ASSERT_TIMELY (5s, node1.peer_cache.exists (node3.network.endpoint ()));

ASSERT_TIMELY (5s, node2.peer_cache.exists (node1.network.endpoint ()));
ASSERT_TIMELY (5s, node2.peer_cache.exists (node3.network.endpoint ()));

ASSERT_TIMELY (5s, node3.peer_cache.exists (node1.network.endpoint ()));
ASSERT_TIMELY (5s, node3.peer_cache.exists (node2.network.endpoint ()));
}

TEST (peer_cache, erase_old)
{
nano::test::system system;

auto & node1 = *system.add_node ();
auto & node2 = *system.add_node ();

ASSERT_TIMELY (5s, node1.peer_cache.exists (node2.network.endpoint ()));
ASSERT_TIMELY (5s, node2.peer_cache.exists (node1.network.endpoint ()));

// Endpoint won't be available after node is stopped
auto node2_endpoint = node2.network.endpoint ();

system.stop_node (node2);

auto cached1 = node1.peer_cache.cached_peers ();
ASSERT_EQ (cached1.size (), 1);
ASSERT_EQ (cached1[0], node2_endpoint);

ASSERT_TIMELY (5s, !node1.peer_cache.exists (node2_endpoint));

auto cached2 = node1.peer_cache.cached_peers ();
ASSERT_EQ (cached2.size (), 0);
}

0 comments on commit cff0921

Please sign in to comment.