From 8eb54ba01a8623d546dbd446d3a864e769c34d5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Fri, 29 Mar 2024 11:08:43 +0100 Subject: [PATCH] Fix disconnected nodes --- nano/test_common/system.cpp | 38 +++++++++++++++++++------------------ nano/test_common/system.hpp | 1 + 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/nano/test_common/system.cpp b/nano/test_common/system.cpp index 3005d4c5eb..df300b0ea9 100644 --- a/nano/test_common/system.cpp +++ b/nano/test_common/system.cpp @@ -75,19 +75,15 @@ void nano::test::system::stop () { logger.debug (nano::log::type::system, "Stopping..."); - // Keep io_context running while stopping - auto stopped = std::async (std::launch::async, [&] { - for (auto & node : nodes) - { - node->stop (); - } - }); - - auto ec = poll_until_true (10s, [&] { - auto status = stopped.wait_for (0s); - return status == std::future_status::ready; - }); - debug_assert (!ec); + // Keep io_context running while stopping nodes + for (auto & node : nodes) + { + stop_node (*node); + } + for (auto & node : disconnected_nodes) + { + stop_node (*node); + } io_guard.reset (); work.stop (); @@ -120,8 +116,9 @@ std::shared_ptr nano::test::system::add_node (nano::node_config cons wallet->insert_adhoc (rep->prv); } node->start (); - nodes.reserve (nodes.size () + 1); nodes.push_back (node); + + // Connect with other nodes if (nodes.size () > 1) { debug_assert (nodes.size () - 1 <= node->network_params.network.max_peers_per_ip || node->flags.disable_max_peers_per_ip); // Check that we don't start more nodes than limit for single IP address @@ -197,17 +194,22 @@ std::shared_ptr nano::test::system::add_node (nano::node_config cons return node; } +// TODO: Merge with add_node std::shared_ptr nano::test::system::make_disconnected_node (std::optional opt_node_config, nano::node_flags flags) { nano::node_config node_config = opt_node_config.has_value () ? *opt_node_config : default_config (); auto node = std::make_shared (io_ctx, nano::unique_path (), node_config, work, flags); - if (node->init_error ()) + for (auto i : initialization_blocks) { - std::cerr << "node init error\n"; - return nullptr; + auto result = node->ledger.process (node->store.tx_begin_write (), i); + debug_assert (result == nano::block_status::progress); } + debug_assert (!node->init_error ()); node->start (); - nodes.push_back (node); + disconnected_nodes.push_back (node); + + logger.debug (nano::log::type::system, "Node started (disconnected): {}", node->get_node_id ().to_node_id ()); + return node; } diff --git a/nano/test_common/system.hpp b/nano/test_common/system.hpp index e0c9f127ca..971319818c 100644 --- a/nano/test_common/system.hpp +++ b/nano/test_common/system.hpp @@ -80,6 +80,7 @@ namespace test std::shared_ptr io_ctx; boost::asio::executor_work_guard io_guard; std::vector> nodes; + std::vector> disconnected_nodes; nano::stats stats; nano::logger logger{ "tests" }; nano::work_pool work{ nano::dev::network_params.network, std::max (nano::hardware_concurrency (), 1u) };