From f07ba9c88839a0e66f32abb881a0bde43e6d4932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Tue, 16 Apr 2024 11:58:32 +0200 Subject: [PATCH] RECONNECT CACHED TEST --- nano/core_test/network.cpp | 48 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/nano/core_test/network.cpp b/nano/core_test/network.cpp index be876bdf07..ddf0345c28 100644 --- a/nano/core_test/network.cpp +++ b/nano/core_test/network.cpp @@ -17,6 +17,8 @@ #include #include +#include + using namespace std::chrono_literals; TEST (network, tcp_connection) @@ -1196,3 +1198,49 @@ TEST (network, purge_dead_channel_incoming) ASSERT_TRUE (channel2); ASSERT_TRUE (channel2->alive ()); } + +TEST (network, reconnect_cached) +{ + nano::test::system system; + + nano::node_flags flags; + // Disable non realtime sockets + flags.disable_bootstrap_bulk_push_client = true; + flags.disable_bootstrap_bulk_pull_server = true; + flags.disable_bootstrap_listener = true; + flags.disable_lazy_bootstrap = true; + flags.disable_legacy_bootstrap = true; + flags.disable_wallet_bootstrap = true; + + auto & node1 = *system.add_node (flags); + auto & node2 = *system.add_node (flags); + + ASSERT_EQ (node1.network.size (), 1); + ASSERT_EQ (node2.network.size (), 1); + + // Store channels + auto channels1 = node1.network.list (); + auto channels2 = node2.network.list (); + ASSERT_EQ (channels1.size (), 1); + ASSERT_EQ (channels2.size (), 1); + auto channel1 = channels1.front (); + auto channel2 = channels2.front (); + + // Kill channels + channel1->close (); + channel2->close (); + + auto channel_exists = [] (auto & node, auto & channel) { + auto channels = node.network.list (); + return std::find (channels.begin (), channels.end (), channel) != channels.end (); + }; + + ASSERT_TIMELY (5s, !channel_exists (node1, channel1)); + ASSERT_TIMELY (5s, !channel_exists (node2, channel2)); + + // Peers should reconnect after a while + ASSERT_TIMELY_EQ (5s, node1.network.size (), 1); + ASSERT_TIMELY_EQ (5s, node2.network.size (), 1); + ASSERT_TRUE (node1.network.find_node_id (node2.node_id.pub)); + ASSERT_TRUE (node2.network.find_node_id (node1.node_id.pub)); +} \ No newline at end of file