Skip to content

Commit

Permalink
Merge pull request #4525 from pwojcikdev/networking-fixes/io-context-…
Browse files Browse the repository at this point in the history
…stopping

Keep io context running when stopping test system
  • Loading branch information
pwojcikdev authored Mar 30, 2024
2 parents f942d90 + 8eb54ba commit 0b83fa6
Show file tree
Hide file tree
Showing 20 changed files with 148 additions and 153 deletions.
24 changes: 0 additions & 24 deletions nano/core_test/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ TEST (bootstrap_processor, process_none)

node1->bootstrap_initiator.bootstrap (system.nodes[0]->network.endpoint (), false);
ASSERT_TIMELY (5s, done);
node1->stop ();
}

// Bootstrap can pull one basic block
Expand All @@ -320,7 +319,6 @@ TEST (bootstrap_processor, process_one)
ASSERT_NE (node0->latest (nano::dev::genesis_key.pub), node1->latest (nano::dev::genesis_key.pub));
node1->bootstrap_initiator.bootstrap (node0->network.endpoint (), false);
ASSERT_TIMELY_EQ (10s, node1->latest (nano::dev::genesis_key.pub), node0->latest (nano::dev::genesis_key.pub));
node1->stop ();
}

TEST (bootstrap_processor, process_two)
Expand All @@ -341,7 +339,6 @@ TEST (bootstrap_processor, process_two)
ASSERT_NE (node1->latest (nano::dev::genesis_key.pub), node0->latest (nano::dev::genesis_key.pub)); // nodes should be out of sync here
node1->bootstrap_initiator.bootstrap (node0->network.endpoint (), false); // bootstrap triggered
ASSERT_TIMELY_EQ (5s, node1->latest (nano::dev::genesis_key.pub), node0->latest (nano::dev::genesis_key.pub)); // nodes should sync up
node1->stop ();
}

// Bootstrap can pull universal blocks
Expand Down Expand Up @@ -387,7 +384,6 @@ TEST (bootstrap_processor, process_state)
ASSERT_NE (node1->latest (nano::dev::genesis_key.pub), block2->hash ());
node1->bootstrap_initiator.bootstrap (node0->network.endpoint (), false);
ASSERT_TIMELY_EQ (5s, node1->latest (nano::dev::genesis_key.pub), block2->hash ());
node1->stop ();
}

TEST (bootstrap_processor, process_new)
Expand Down Expand Up @@ -426,7 +422,6 @@ TEST (bootstrap_processor, process_new)
auto node3 = system.make_disconnected_node ();
node3->bootstrap_initiator.bootstrap (node1->network.endpoint (), false);
ASSERT_TIMELY_EQ (5s, node3->balance (key2.pub), amount);
node3->stop ();
}

TEST (bootstrap_processor, pull_diamond)
Expand Down Expand Up @@ -478,7 +473,6 @@ TEST (bootstrap_processor, pull_diamond)
auto node1 = system.make_disconnected_node ();
node1->bootstrap_initiator.bootstrap (node0->network.endpoint (), false);
ASSERT_TIMELY_EQ (5s, node1->balance (nano::dev::genesis_key.pub), 100);
node1->stop ();
}

TEST (bootstrap_processor, DISABLED_pull_requeue_network_error)
Expand Down Expand Up @@ -517,7 +511,6 @@ TEST (bootstrap_processor, DISABLED_pull_requeue_network_error)
++attempt->pulling;
node1->bootstrap_initiator.connections->pulls.emplace_back (nano::dev::genesis_key.pub, send1->hash (), nano::dev::genesis->hash (), attempt->incremental_id);
node1->bootstrap_initiator.connections->request_pull (lock);
node2->stop ();
}
ASSERT_TIMELY (5s, attempt == nullptr || attempt->requeued_pulls == 1);
ASSERT_EQ (0, node1->stats.count (nano::stat::type::bootstrap, nano::stat::detail::bulk_pull_failed_account, nano::stat::dir::in)); // Requeue is not increasing failed attempts
Expand Down Expand Up @@ -586,7 +579,6 @@ TEST (bootstrap_processor, push_diamond)
auto node2 = system.add_node (config, flags);
node1->bootstrap_initiator.bootstrap (node2->network.endpoint (), false);
ASSERT_TIMELY_EQ (5s, node2->balance (nano::dev::genesis_key.pub), 100);
node1->stop ();
}

TEST (bootstrap_processor, push_diamond_pruning)
Expand Down Expand Up @@ -677,7 +669,6 @@ TEST (bootstrap_processor, push_diamond_pruning)
node1->bootstrap_initiator.bootstrap (node0->network.endpoint (), false);
ASSERT_TIMELY_EQ (5s, node0->balance (nano::dev::genesis_key.pub), 100);
ASSERT_TIMELY_EQ (5s, node1->balance (nano::dev::genesis_key.pub), 100);
node1->stop ();
}

TEST (bootstrap_processor, push_one)
Expand All @@ -700,7 +691,6 @@ TEST (bootstrap_processor, push_one)

node1->bootstrap_initiator.bootstrap (node0->network.endpoint (), false);
ASSERT_TIMELY_EQ (5s, node0->balance (nano::dev::genesis_key.pub), genesis_balance - 100);
node1->stop ();
}

TEST (bootstrap_processor, lazy_hash)
Expand Down Expand Up @@ -775,7 +765,6 @@ TEST (bootstrap_processor, lazy_hash)
}
// Check processed blocks
ASSERT_TIMELY (10s, node1->balance (key2.pub) != 0);
node1->stop ();
}

TEST (bootstrap_processor, lazy_hash_bootstrap_id)
Expand Down Expand Up @@ -850,7 +839,6 @@ TEST (bootstrap_processor, lazy_hash_bootstrap_id)
}
// Check processed blocks
ASSERT_TIMELY (10s, node1->balance (key2.pub) != 0);
node1->stop ();
}

TEST (bootstrap_processor, lazy_hash_pruning)
Expand Down Expand Up @@ -1003,7 +991,6 @@ TEST (bootstrap_processor, lazy_hash_pruning)
ASSERT_TIMELY_EQ (5s, node1->ledger.cache.block_count, 9);
ASSERT_TIMELY (5s, node1->balance (key2.pub) != 0);
ASSERT_TIMELY (5s, !node1->bootstrap_initiator.in_progress ());
node1->stop ();
}

TEST (bootstrap_processor, lazy_max_pull_count)
Expand Down Expand Up @@ -1105,7 +1092,6 @@ TEST (bootstrap_processor, lazy_max_pull_count)
node1->bootstrap_initiator.bootstrap_lazy (change3->hash ());
// Check processed blocks
ASSERT_TIMELY (10s, node1->block (change3->hash ()));
node1->stop ();
}

TEST (bootstrap_processor, lazy_unclear_state_link)
Expand Down Expand Up @@ -1174,7 +1160,6 @@ TEST (bootstrap_processor, lazy_unclear_state_link)
node2->bootstrap_initiator.bootstrap_lazy (receive->hash ());
ASSERT_TIMELY (5s, nano::test::exists (*node2, { send1, send2, open, receive }));
ASSERT_EQ (0, node2->stats.count (nano::stat::type::bootstrap, nano::stat::detail::bulk_pull_failed_account, nano::stat::dir::in));
node2->stop ();
}

TEST (bootstrap_processor, lazy_unclear_state_link_not_existing)
Expand Down Expand Up @@ -1233,7 +1218,6 @@ TEST (bootstrap_processor, lazy_unclear_state_link_not_existing)
ASSERT_TIMELY (15s, !node2->bootstrap_initiator.in_progress ());
ASSERT_TIMELY (15s, nano::test::block_or_pruned_all_exists (*node2, { send1, open, send2 }));
ASSERT_EQ (1, node2->stats.count (nano::stat::type::bootstrap, nano::stat::detail::bulk_pull_failed_account, nano::stat::dir::in));
node2->stop ();
}

TEST (bootstrap_processor, lazy_destinations)
Expand Down Expand Up @@ -1312,7 +1296,6 @@ TEST (bootstrap_processor, lazy_destinations)
ASSERT_TIMELY (5s, node2->ledger.block_or_pruned_exists (send2->hash ()));
ASSERT_FALSE (node2->ledger.block_or_pruned_exists (open->hash ()));
ASSERT_FALSE (node2->ledger.block_or_pruned_exists (state_open->hash ()));
node2->stop ();
}

TEST (bootstrap_processor, lazy_pruning_missing_block)
Expand Down Expand Up @@ -1421,7 +1404,6 @@ TEST (bootstrap_processor, lazy_pruning_missing_block)
ASSERT_TIMELY_EQ (5s, 3, node2->ledger.cache.block_count);
ASSERT_TIMELY (5s, nano::test::exists (*node2, { send1, send2 }));
ASSERT_TRUE (nano::test::block_or_pruned_none_exists (*node2, { open, state_open }));
node2->stop ();
}

TEST (bootstrap_processor, lazy_cancel)
Expand Down Expand Up @@ -1456,7 +1438,6 @@ TEST (bootstrap_processor, lazy_cancel)
}
// Cancel failing lazy bootstrap
ASSERT_TIMELY (10s, !node1->bootstrap_initiator.in_progress ());
node1->stop ();
}

TEST (bootstrap_processor, wallet_lazy_frontier)
Expand Down Expand Up @@ -1537,7 +1518,6 @@ TEST (bootstrap_processor, wallet_lazy_frontier)
}
// Check processed blocks
ASSERT_TIMELY (10s, node1->ledger.block_or_pruned_exists (receive2->hash ()));
node1->stop ();
}

TEST (bootstrap_processor, wallet_lazy_pending)
Expand Down Expand Up @@ -1684,7 +1664,6 @@ TEST (bootstrap_processor, multiple_attempts)
ASSERT_TIMELY (10s, node2->balance (key2.pub) != 0);
// Check attempts finish
ASSERT_TIMELY_EQ (5s, node2->bootstrap_initiator.attempts.size (), 0);
node2->stop ();
}

TEST (frontier_req_response, DISABLED_destruction)
Expand Down Expand Up @@ -1996,7 +1975,6 @@ TEST (bulk, genesis)
node2->bootstrap_initiator.bootstrap (node1->network.endpoint (), false);
ASSERT_TIMELY_EQ (10s, node2->latest (nano::dev::genesis_key.pub), node1->latest (nano::dev::genesis_key.pub));
ASSERT_EQ (node2->latest (nano::dev::genesis_key.pub), node1->latest (nano::dev::genesis_key.pub));
node2->stop ();
}

TEST (bulk, offline_send)
Expand Down Expand Up @@ -2036,7 +2014,6 @@ TEST (bulk, offline_send)
ASSERT_TIMELY_EQ (5s, node2->balance (nano::dev::genesis_key.pub), std::numeric_limits<nano::uint128_t>::max () - amount);
// Receiving send block
ASSERT_TIMELY_EQ (5s, node2->balance (key2.pub), amount);
node2->stop ();
}

TEST (bulk, genesis_pruning)
Expand Down Expand Up @@ -2115,7 +2092,6 @@ TEST (bulk, genesis_pruning)
ASSERT_TIMELY_EQ (5s, node2->bootstrap_initiator.connections->connections_count, 0);
node2->bootstrap_initiator.bootstrap (node1->network.endpoint (), false);
ASSERT_TIMELY_EQ (5s, node2->latest (nano::dev::genesis_key.pub), node1->latest (nano::dev::genesis_key.pub));
node2->stop ();
}

TEST (bulk_pull_account, basics)
Expand Down
39 changes: 1 addition & 38 deletions nano/core_test/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ TEST (network, send_node_id_handshake_tcp)
auto list2 (node1->network.list (1));
ASSERT_EQ (nano::transport::transport_type::tcp, list2[0]->get_type ());
ASSERT_EQ (node0->get_node_id (), list2[0]->get_node_id ());
node1->stop ();
}

TEST (network, last_contacted)
Expand Down Expand Up @@ -531,46 +530,10 @@ TEST (network, ipv6_from_ipv4)
ASSERT_TRUE (endpoint2.address ().is_v6 ());
}

TEST (network, ipv6_bind_send_ipv4)
{
nano::test::system system;
nano::endpoint endpoint1 (boost::asio::ip::address_v6::any (), 0);
nano::endpoint endpoint2 (boost::asio::ip::address_v4::any (), 0);
std::array<uint8_t, 16> bytes1{};
std::atomic<bool> finish1{ false };
nano::endpoint endpoint3;
boost::asio::ip::udp::socket socket1 (*system.io_ctx, endpoint1);
socket1.async_receive_from (boost::asio::buffer (bytes1.data (), bytes1.size ()), endpoint3, [&finish1] (boost::system::error_code const & error, size_t size_a) {
ASSERT_FALSE (error);
ASSERT_EQ (16, size_a);
finish1 = true;
});
boost::asio::ip::udp::socket socket2 (*system.io_ctx, endpoint2);
nano::endpoint endpoint5 (boost::asio::ip::address_v4::loopback (), socket1.local_endpoint ().port ());
nano::endpoint endpoint6 (boost::asio::ip::address_v6::v4_mapped (boost::asio::ip::address_v4::loopback ()), socket2.local_endpoint ().port ());
socket2.async_send_to (boost::asio::buffer (std::array<uint8_t, 16>{}, 16), endpoint5, [] (boost::system::error_code const & error, size_t size_a) {
ASSERT_FALSE (error);
ASSERT_EQ (16, size_a);
});
auto iterations (0);
ASSERT_TIMELY (5s, finish1);
ASSERT_EQ (endpoint6, endpoint3);
std::array<uint8_t, 16> bytes2;
nano::endpoint endpoint4;
socket2.async_receive_from (boost::asio::buffer (bytes2.data (), bytes2.size ()), endpoint4, [] (boost::system::error_code const & error, size_t size_a) {
ASSERT_FALSE (!error);
ASSERT_EQ (16, size_a);
});
socket1.async_send_to (boost::asio::buffer (std::array<uint8_t, 16>{}, 16), endpoint6, [] (boost::system::error_code const & error, size_t size_a) {
ASSERT_FALSE (error);
ASSERT_EQ (16, size_a);
});
}

TEST (network, endpoint_bad_fd)
{
nano::test::system system (1);
system.nodes[0]->stop ();
system.stop_node (*system.nodes[0]);
auto endpoint (system.nodes[0]->network.endpoint ());
ASSERT_TRUE (endpoint.address ().is_loopback ());
// The endpoint is invalidated asynchronously
Expand Down
20 changes: 6 additions & 14 deletions nano/core_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ TEST (node, stop)
{
nano::test::system system (1);
ASSERT_NE (system.nodes[0]->wallets.items.end (), system.nodes[0]->wallets.items.begin ());
system.nodes[0]->stop ();
system.io_ctx->run ();
ASSERT_TRUE (true);
}

Expand Down Expand Up @@ -77,9 +75,10 @@ TEST (node, block_store_path_failure)
auto path (nano::unique_path ());
nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };
auto node (std::make_shared<nano::node> (io_ctx, system.get_available_port (), path, pool));
system.register_node (node);
ASSERT_TRUE (node->wallets.items.empty ());
node->stop ();
}

#if defined(__clang__) && defined(__linux__) && CI
// Disable test due to instability with clang and actions
TEST (node_DeathTest, DISABLED_readonly_block_store_not_exist)
Expand All @@ -102,16 +101,13 @@ TEST (node_DeathTest, readonly_block_store_not_exist)
TEST (node, password_fanout)
{
nano::test::system system;
auto io_ctx = std::make_shared<boost::asio::io_context> ();
auto path (nano::unique_path ());
nano::node_config config;
config.peering_port = system.get_available_port ();
nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };
config.password_fanout = 10;
nano::node node (io_ctx, path, config, pool);
auto & node = *system.add_node (config);
auto wallet (node.wallets.create (100));
ASSERT_EQ (10, wallet->store.password.values.size ());
node.stop ();
}

TEST (node, balance)
Expand Down Expand Up @@ -284,8 +280,6 @@ TEST (node, auto_bootstrap)
ASSERT_TIMELY_EQ (5s, node1->ledger.cache.block_count, 3);
// Confirmation for all blocks
ASSERT_TIMELY_EQ (5s, node1->ledger.cache.cemented_count, 3);

node1->stop ();
}

TEST (node, auto_bootstrap_reverse)
Expand Down Expand Up @@ -329,8 +323,6 @@ TEST (node, auto_bootstrap_age)
ASSERT_TIMELY (10s, node0->stats.count (nano::stat::type::bootstrap, nano::stat::detail::initiate_legacy_age, nano::stat::dir::out) >= 3);
// More attempts with frontiers age
ASSERT_GE (node0->stats.count (nano::stat::type::bootstrap, nano::stat::detail::initiate_legacy_age, nano::stat::dir::out), node0->stats.count (nano::stat::type::bootstrap, nano::stat::detail::initiate, nano::stat::dir::out));

node1->stop ();
}

TEST (node, merge_peers)
Expand Down Expand Up @@ -2843,7 +2835,7 @@ TEST (node, peers)
ASSERT_TRUE (store.peer.exists (store.tx_begin_read (), endpoint_key));

// Stop the peer node and check that it is removed from the store
node1->stop ();
system.stop_node (*node1);

// TODO: In `tcp_channels::store_all` we skip store operation when there are no peers present,
// so the best we can do here is check if network is empty
Expand Down Expand Up @@ -2873,7 +2865,7 @@ TEST (node, peer_cache_restart)
auto list (node2->network.list (2));
ASSERT_EQ (node1->network.endpoint (), list[0]->get_endpoint ());
ASSERT_EQ (1, node2->network.size ());
node2->stop ();
system.stop_node (*node2);
}
// Restart node
{
Expand All @@ -2896,7 +2888,7 @@ TEST (node, peer_cache_restart)
auto list (node3->network.list (2));
ASSERT_EQ (node1->network.endpoint (), list[0]->get_endpoint ());
ASSERT_EQ (1, node3->network.size ());
node3->stop ();
system.stop_node (*node3);
}
}

Expand Down
4 changes: 2 additions & 2 deletions nano/core_test/rep_crawler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ TEST (rep_crawler, rep_remove)
ASSERT_TIMELY_EQ (10s, searching_node.rep_crawler.representative_count (), 2);

// When Rep2 is stopped, it should not be found as principal representative anymore
node_rep2->stop ();
system.stop_node (*node_rep2);
ASSERT_TIMELY_EQ (10s, searching_node.rep_crawler.representative_count (), 1);

// Now only genesisRep should be found:
Expand All @@ -239,7 +239,7 @@ TEST (rep_crawler, rep_connection_close)
// Add working representative (node 2)
system.wallet (1)->insert_adhoc (nano::dev::genesis_key.prv);
ASSERT_TIMELY_EQ (10s, node1.rep_crawler.representative_count (), 1);
node2.stop ();
system.stop_node (node2);
// Remove representative with closed channel
ASSERT_TIMELY_EQ (10s, node1.rep_crawler.representative_count (), 0);
}
Expand Down
Loading

0 comments on commit 0b83fa6

Please sign in to comment.