Skip to content

Commit

Permalink
FIX
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Mar 29, 2024
1 parent 20c74bd commit f64fce2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
37 changes: 19 additions & 18 deletions nano/test_common/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,14 @@ 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);
for (auto & node : nodes)
{
stop_node (*node);
}
for (auto & node : disconnected_nodes)
{
stop_node (*node);
}

io_guard.reset ();
work.stop ();
Expand Down Expand Up @@ -120,8 +115,9 @@ std::shared_ptr<nano::node> 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
Expand Down Expand Up @@ -197,17 +193,22 @@ std::shared_ptr<nano::node> nano::test::system::add_node (nano::node_config cons
return node;
}

// TODO: Merge with add_node
std::shared_ptr<nano::node> nano::test::system::make_disconnected_node (std::optional<nano::node_config> 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<nano::node> (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;
}

Expand Down
1 change: 1 addition & 0 deletions nano/test_common/system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ namespace test
std::shared_ptr<boost::asio::io_context> io_ctx;
boost::asio::executor_work_guard<boost::asio::io_context::executor_type> io_guard;
std::vector<std::shared_ptr<nano::node>> nodes;
std::vector<std::shared_ptr<nano::node>> disconnected_nodes;
nano::stats stats;
nano::logger logger{ "tests" };
nano::work_pool work{ nano::dev::network_params.network, std::max (nano::hardware_concurrency (), 1u) };
Expand Down

0 comments on commit f64fce2

Please sign in to comment.