diff --git a/nano/core_test/network.cpp b/nano/core_test/network.cpp index 2ee6cddf06..a7c7601d73 100644 --- a/nano/core_test/network.cpp +++ b/nano/core_test/network.cpp @@ -1100,6 +1100,57 @@ TEST (network, fill_keepalive_self) ASSERT_EQ (target[2].port (), system.nodes[1]->network.port); } +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); + + 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 (); + + // Enusre current peers are cached + node1.peer_cache.trigger (); + node2.peer_cache.trigger (); + ASSERT_TIMELY_EQ (5s, node1.peer_cache.size (), 1); + ASSERT_TIMELY_EQ (5s, node2.peer_cache.size (), 1); + + // 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)); +} + /* * Tests that channel and channel container removes channels with dead local sockets */