diff options
| author | j-berman <justinberman@protonmail.com> | 2026-03-17 19:39:13 -0700 |
|---|---|---|
| committer | j-berman <justinberman@protonmail.com> | 2026-04-04 15:02:49 -0700 |
| commit | 7bc2d5a42e8462f2a04f71bd59111a863fa9a6d8 (patch) | |
| tree | 90d8e4661f991777b4dedf996da8455bbbc2f6c9 /tests/unit_tests/node_server.cpp | |
| parent | 1df631970fa610824117c85e05afddcedcdf8196 (diff) | |
| download | monzero-core-7bc2d5a42e8462f2a04f71bd59111a863fa9a6d8.tar.gz monzero-core-7bc2d5a42e8462f2a04f71bd59111a863fa9a6d8.tar.xz monzero-core-7bc2d5a42e8462f2a04f71bd59111a863fa9a6d8.zip | |
p2p: fix hanging shutdown
Diffstat (limited to 'tests/unit_tests/node_server.cpp')
| -rw-r--r-- | tests/unit_tests/node_server.cpp | 53 |
1 files changed, 19 insertions, 34 deletions
diff --git a/tests/unit_tests/node_server.cpp b/tests/unit_tests/node_server.cpp index e55b43911..11853c0fd 100644 --- a/tests/unit_tests/node_server.cpp +++ b/tests/unit_tests/node_server.cpp @@ -42,6 +42,21 @@ #define MAKE_IPV4_ADDRESS_PORT(a,b,c,d,e) epee::net_utils::ipv4_network_address{MAKE_IP(a,b,c,d),e} #define MAKE_IPV4_SUBNET(a,b,c,d,e) epee::net_utils::ipv4_network_subnet{MAKE_IP(a,b,c,d),e} +namespace +{ + boost::filesystem::path create_temp_dir() + { + boost::system::error_code ec; + auto path = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path("daemon-%%%%%%%%%%%%%%%%", ec); + if (ec) + return boost::filesystem::path{}; + auto success = boost::filesystem::create_directory(path, ec); + if (!ec && success) + return path; + return boost::filesystem::path{}; + } +} + namespace cryptonote { class blockchain_storage; } @@ -300,17 +315,7 @@ TEST(ban, file_banlist) Server server(cprotocol); cprotocol.set_p2p_endpoint(&server); - auto create_node_dir = [](){ - boost::system::error_code ec; - auto path = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path("daemon-%%%%%%%%%%%%%%%%", ec); - if (ec) - return boost::filesystem::path{}; - auto success = boost::filesystem::create_directory(path, ec); - if (!ec && success) - return path; - return boost::filesystem::path{}; - }; - const auto node_dir = create_node_dir(); + const auto node_dir = create_temp_dir(); ASSERT_TRUE(!node_dir.empty()); auto auto_remove_node_dir = epee::misc_utils::create_scope_leave_handler([&node_dir](){ boost::filesystem::remove_all(node_dir); @@ -615,7 +620,7 @@ TEST(cryptonote_protocol_handler, race_condition) } virtual bool drop_connection(const contexts::basic& context) override { if (shared_state) - return shared_state->close(context.m_connection_id); + return shared_state->close(context.m_connection_id, true); else return {}; } @@ -697,16 +702,6 @@ TEST(cryptonote_protocol_handler, race_condition) handshaked.wait(); }; using path_t = boost::filesystem::path; - auto create_dir = []{ - ec_t ec; - path_t path = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path("daemon-%%%%%%%%%%%%%%%%", ec); - if (ec) - return path_t{}; - auto success = boost::filesystem::create_directory(path, ec); - if (not ec && success) - return path; - return path_t{}; - }; auto remove_tree = [](const path_t &path){ ec_t ec; boost::filesystem::remove_all(path, ec); @@ -726,7 +721,7 @@ TEST(cryptonote_protocol_handler, race_condition) }; using options_description_t = boost::program_options::options_description; - const auto dir = create_dir(); + const auto dir = create_temp_dir(); ASSERT_TRUE(not dir.empty()); daemons_t daemon{ @@ -1215,21 +1210,11 @@ TEST(node_server, race_condition) }; using path_t = boost::filesystem::path; using ec_t = boost::system::error_code; - auto create_dir = []{ - ec_t ec; - path_t path = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path("daemon-%%%%%%%%%%%%%%%%", ec); - if (ec) - return path_t{}; - auto success = boost::filesystem::create_directory(path, ec); - if (not ec && success) - return path; - return path_t{}; - }; auto remove_tree = [](const path_t &path){ ec_t ec; boost::filesystem::remove_all(path, ec); }; - const auto dir = create_dir(); + const auto dir = create_temp_dir(); ASSERT_TRUE(not dir.empty()); protocol_t protocol{}; node_server_t node_server(protocol); |
