From 01bcd52924244ec8d2a24c10fcef8959289d09ff Mon Sep 17 00:00:00 2001 From: Lee *!* Clagett Date: Tue, 17 Dec 2024 16:40:15 -0500 Subject: Fix build with boost ASIO 0.87. Support boost 1.66+ --- tests/unit_tests/epee_boosted_tcp_server.cpp | 39 ++++--- .../epee_levin_protocol_handler_async.cpp | 8 +- tests/unit_tests/levin.cpp | 114 ++++++++++----------- tests/unit_tests/net.cpp | 20 ++-- tests/unit_tests/node_server.cpp | 38 +++---- 5 files changed, 109 insertions(+), 110 deletions(-) (limited to 'tests/unit_tests') diff --git a/tests/unit_tests/epee_boosted_tcp_server.cpp b/tests/unit_tests/epee_boosted_tcp_server.cpp index c08a86a5e..c56174109 100644 --- a/tests/unit_tests/epee_boosted_tcp_server.cpp +++ b/tests/unit_tests/epee_boosted_tcp_server.cpp @@ -28,6 +28,7 @@ // // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers +#include #include #include #include @@ -173,9 +174,9 @@ TEST(test_epee_connection, test_lifetime) using shared_states_t = std::vector; using tag_t = boost::uuids::uuid; using tags_t = std::vector; - using io_context_t = boost::asio::io_service; + using io_context_t = boost::asio::io_context; using endpoint_t = boost::asio::ip::tcp::endpoint; - using work_t = boost::asio::io_service::work; + using work_t = boost::asio::executor_work_guard; using work_ptr = std::shared_ptr; using workers_t = std::vector; using server_t = epee::net_utils::boosted_tcp_server; @@ -189,7 +190,7 @@ TEST(test_epee_connection, test_lifetime) using shared_conn_ptr = std::shared_ptr; io_context_t io_context; - work_ptr work(std::make_shared(io_context)); + work_ptr work(std::make_shared(io_context.get_executor())); workers_t workers; while (workers.size() < 4) { @@ -198,7 +199,7 @@ TEST(test_epee_connection, test_lifetime) }); } - endpoint_t endpoint(boost::asio::ip::address::from_string("127.0.0.1"), 5262); + endpoint_t endpoint(boost::asio::ip::make_address("127.0.0.1"), 5262); server_t server(epee::net_utils::e_connection_type_P2P); server.init_server(endpoint.port(), endpoint.address().to_string(), @@ -211,7 +212,7 @@ TEST(test_epee_connection, test_lifetime) server.run_server(2, false); server.get_config_shared()->set_handler(new command_handler_t, &command_handler_t::destroy); - io_context.post([&io_context, &work, &endpoint, &server]{ + boost::asio::post(io_context, [&io_context, &work, &endpoint, &server]{ auto scope_exit_handler = epee::misc_utils::create_scope_leave_handler([&work]{ work.reset(); }); @@ -377,9 +378,7 @@ TEST(test_epee_connection, test_lifetime) connection_ptr conn(new connection_t(io_context, s, {}, {})); conn->socket().connect(endpoint); conn->start({}, {}); - io_context.post([conn]{ - conn->cancel(); - }); + boost::asio::post(io_context, [conn] { conn->cancel(); }); conn.reset(); s->del_out_connections(1); while (s->sock_count); @@ -449,9 +448,7 @@ TEST(test_epee_connection, test_lifetime) context_t context; conn->get_context(context); auto tag = context.m_connection_id; - io_context.post([conn]{ - conn->cancel(); - }); + boost::asio::post(io_context, [conn] { conn->cancel(); }); conn.reset(); s->close(tag); while (s->sock_count); @@ -494,7 +491,7 @@ TEST(test_epee_connection, ssl_shutdown) }; using handler_t = epee::levin::async_protocol_handler; - using io_context_t = boost::asio::io_service; + using io_context_t = boost::asio::io_context; using endpoint_t = boost::asio::ip::tcp::endpoint; using server_t = epee::net_utils::boosted_tcp_server; using socket_t = boost::asio::ip::tcp::socket; @@ -502,7 +499,7 @@ TEST(test_epee_connection, ssl_shutdown) using ssl_context_t = boost::asio::ssl::context; using ec_t = boost::system::error_code; - endpoint_t endpoint(boost::asio::ip::address::from_string("127.0.0.1"), 5263); + endpoint_t endpoint(boost::asio::ip::make_address("127.0.0.1"), 5263); server_t server(epee::net_utils::e_connection_type_P2P); server.init_server(endpoint.port(), endpoint.address().to_string(), @@ -537,8 +534,8 @@ TEST(test_epee_connection, ssl_shutdown) TEST(test_epee_connection, ssl_handshake) { - using io_context_t = boost::asio::io_service; - using work_t = boost::asio::io_service::work; + using io_context_t = boost::asio::io_context; + using work_t = boost::asio::executor_work_guard; using work_ptr = std::shared_ptr; using workers_t = std::vector; using socket_t = boost::asio::ip::tcp::socket; @@ -546,7 +543,7 @@ TEST(test_epee_connection, ssl_handshake) using ssl_socket_ptr = std::unique_ptr; using ssl_options_t = epee::net_utils::ssl_options_t; io_context_t io_context; - work_ptr work(std::make_shared(io_context)); + work_ptr work(std::make_shared(io_context.get_executor())); workers_t workers; auto constexpr N = 2; while (workers.size() < N) { @@ -560,12 +557,14 @@ TEST(test_epee_connection, ssl_handshake) ssl_socket_ptr ssl_socket(new ssl_socket_t(io_context, ssl_context)); ssl_socket->next_layer().open(boost::asio::ip::tcp::v4()); for (size_t i = 0; i < N; ++i) { - io_context.post([]{ - std::this_thread::sleep_for(std::chrono::milliseconds(50)); - }); + boost::asio::post( + io_context, + [] { std::this_thread::sleep_for(std::chrono::milliseconds(50)); } + ); } EXPECT_EQ( ssl_options.handshake( + io_context, *ssl_socket, ssl_socket_t::server, {}, @@ -670,7 +669,7 @@ TEST(boosted_tcp_server, strand_deadlock) using server_t = epee::net_utils::boosted_tcp_server; using endpoint_t = boost::asio::ip::tcp::endpoint; - endpoint_t endpoint(boost::asio::ip::address::from_string("127.0.0.1"), 5262); + endpoint_t endpoint(boost::asio::ip::make_address("127.0.0.1"), 5262); server_t server(epee::net_utils::e_connection_type_P2P); server.init_server( endpoint.port(), diff --git a/tests/unit_tests/epee_levin_protocol_handler_async.cpp b/tests/unit_tests/epee_levin_protocol_handler_async.cpp index 38a18695d..9dbb2c19b 100644 --- a/tests/unit_tests/epee_levin_protocol_handler_async.cpp +++ b/tests/unit_tests/epee_levin_protocol_handler_async.cpp @@ -129,7 +129,7 @@ namespace class test_connection : public epee::net_utils::i_service_endpoint { public: - test_connection(boost::asio::io_service& io_service, test_levin_protocol_handler_config& protocol_config) + test_connection(boost::asio::io_context& io_service, test_levin_protocol_handler_config& protocol_config) : m_io_service(io_service) , m_protocol_handler(this, protocol_config, m_context) , m_send_return(true) @@ -155,7 +155,7 @@ namespace virtual bool send_done() { /*std::cout << "test_connection::send_done()" << std::endl; */return true; } virtual bool call_run_once_service_io() { std::cout << "test_connection::call_run_once_service_io()" << std::endl; return true; } virtual bool request_callback() { std::cout << "test_connection::request_callback()" << std::endl; return true; } - virtual boost::asio::io_service& get_io_service() { std::cout << "test_connection::get_io_service()" << std::endl; return m_io_service; } + virtual boost::asio::io_context& get_io_context() { std::cout << "test_connection::get_io_context()" << std::endl; return m_io_service; } virtual bool add_ref() { std::cout << "test_connection::add_ref()" << std::endl; return true; } virtual bool release() { std::cout << "test_connection::release()" << std::endl; return true; } @@ -171,7 +171,7 @@ namespace test_levin_protocol_handler m_protocol_handler; private: - boost::asio::io_service& m_io_service; + boost::asio::io_context& m_io_service; test_levin_connection_context m_context; unit_test::call_counter m_send_counter; @@ -216,7 +216,7 @@ namespace } protected: - boost::asio::io_service m_io_service; + boost::asio::io_context m_io_service; test_levin_protocol_handler_config m_handler_config; test_levin_commands_handler *m_pcommands_handler, &m_commands_handler; }; diff --git a/tests/unit_tests/levin.cpp b/tests/unit_tests/levin.cpp index 6eac92de7..25b67907f 100644 --- a/tests/unit_tests/levin.cpp +++ b/tests/unit_tests/levin.cpp @@ -54,7 +54,7 @@ namespace { class test_endpoint final : public epee::net_utils::i_service_endpoint { - boost::asio::io_service& io_service_; + boost::asio::io_context& io_service_; std::size_t ref_count_; virtual bool do_send(epee::byte_slice message) override final @@ -83,7 +83,7 @@ namespace throw std::logic_error{"request_callback not implemented"}; } - virtual boost::asio::io_service& get_io_service() override final + virtual boost::asio::io_context& get_io_context() override final { return io_service_; } @@ -101,7 +101,7 @@ namespace } public: - test_endpoint(boost::asio::io_service& io_service) + test_endpoint(boost::asio::io_context& io_service) : epee::net_utils::i_service_endpoint(), io_service_(io_service), ref_count_(0), @@ -171,7 +171,7 @@ namespace epee::levin::async_protocol_handler handler_; public: - test_connection(boost::asio::io_service& io_service, cryptonote::levin::connections& connections, boost::uuids::random_generator& random_generator, const bool is_incoming) + test_connection(boost::asio::io_context& io_service, cryptonote::levin::connections& connections, boost::uuids::random_generator& random_generator, const bool is_incoming) : endpoint_(io_service), context_(), handler_(std::addressof(endpoint_), connections, context_) @@ -364,7 +364,7 @@ namespace } boost::uuids::random_generator random_generator_; - boost::asio::io_service io_service_; + boost::asio::io_context io_service_; test_receiver receiver_; std::deque contexts_; test_core_events events_; @@ -626,7 +626,7 @@ TEST_F(levin_notify, fluff_without_padding) auto context = contexts_.begin(); EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::fluff)); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); notifier.run_fluff(); ASSERT_LT(0u, io_service_.poll()); @@ -680,7 +680,7 @@ TEST_F(levin_notify, stem_without_padding) auto context = contexts_.begin(); EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::stem)); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); const bool is_stem = events_.has_stem_txes(); EXPECT_EQ(txs, events_.take_relayed(is_stem ? cryptonote::relay_method::stem : cryptonote::relay_method::fluff)); @@ -751,7 +751,7 @@ TEST_F(levin_notify, stem_no_outs_without_padding) auto context = contexts_.begin(); EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::stem)); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::fluff)); if (events_.has_stem_txes()) @@ -820,7 +820,7 @@ TEST_F(levin_notify, local_without_padding) auto context = contexts_.begin(); EXPECT_TRUE(notifier.send_txs(their_txs, context->get_id(), cryptonote::relay_method::stem)); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); const bool is_stem = events_.has_stem_txes(); EXPECT_EQ(their_txs, events_.take_relayed(is_stem ? cryptonote::relay_method::stem : cryptonote::relay_method::fluff)); @@ -860,7 +860,7 @@ TEST_F(levin_notify, local_without_padding) context = contexts_.begin(); EXPECT_TRUE(notifier.send_txs(my_txs, context->get_id(), cryptonote::relay_method::local)); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); EXPECT_TRUE(events_.has_stem_txes()); EXPECT_EQ(my_txs, events_.take_relayed(cryptonote::relay_method::stem)); @@ -922,7 +922,7 @@ TEST_F(levin_notify, forward_without_padding) auto context = contexts_.begin(); EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::forward)); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); const bool is_stem = events_.has_stem_txes(); EXPECT_EQ(txs, events_.take_relayed(is_stem ? cryptonote::relay_method::stem : cryptonote::relay_method::fluff)); @@ -990,7 +990,7 @@ TEST_F(levin_notify, block_without_padding) auto context = contexts_.begin(); EXPECT_FALSE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::block)); - io_service_.reset(); + io_service_.restart(); ASSERT_EQ(0u, io_service_.poll()); } } @@ -1021,7 +1021,7 @@ TEST_F(levin_notify, none_without_padding) auto context = contexts_.begin(); EXPECT_FALSE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::none)); - io_service_.reset(); + io_service_.restart(); ASSERT_EQ(0u, io_service_.poll()); } } @@ -1052,7 +1052,7 @@ TEST_F(levin_notify, fluff_with_padding) auto context = contexts_.begin(); EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::fluff)); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); notifier.run_fluff(); ASSERT_LT(0u, io_service_.poll()); @@ -1103,7 +1103,7 @@ TEST_F(levin_notify, stem_with_padding) auto context = contexts_.begin(); EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::stem)); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); const bool is_stem = events_.has_stem_txes(); EXPECT_EQ(txs, events_.take_relayed(is_stem ? cryptonote::relay_method::stem : cryptonote::relay_method::fluff)); @@ -1172,7 +1172,7 @@ TEST_F(levin_notify, stem_no_outs_with_padding) auto context = contexts_.begin(); EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::stem)); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::fluff)); if (events_.has_stem_txes()) @@ -1235,7 +1235,7 @@ TEST_F(levin_notify, local_with_padding) auto context = contexts_.begin(); EXPECT_TRUE(notifier.send_txs(their_txs, context->get_id(), cryptonote::relay_method::stem)); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); const bool is_stem = events_.has_stem_txes(); EXPECT_EQ(their_txs, events_.take_relayed(is_stem ? cryptonote::relay_method::stem : cryptonote::relay_method::fluff)); @@ -1273,7 +1273,7 @@ TEST_F(levin_notify, local_with_padding) context = contexts_.begin(); EXPECT_TRUE(notifier.send_txs(my_txs, context->get_id(), cryptonote::relay_method::local)); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); EXPECT_TRUE(events_.has_stem_txes()); EXPECT_EQ(my_txs, events_.take_relayed(cryptonote::relay_method::stem)); @@ -1332,7 +1332,7 @@ TEST_F(levin_notify, forward_with_padding) auto context = contexts_.begin(); EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::forward)); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); const bool is_stem = events_.has_stem_txes(); EXPECT_EQ(txs, events_.take_relayed(is_stem ? cryptonote::relay_method::stem : cryptonote::relay_method::fluff)); @@ -1398,7 +1398,7 @@ TEST_F(levin_notify, block_with_padding) auto context = contexts_.begin(); EXPECT_FALSE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::block)); - io_service_.reset(); + io_service_.restart(); ASSERT_EQ(0u, io_service_.poll()); } } @@ -1429,7 +1429,7 @@ TEST_F(levin_notify, none_with_padding) auto context = contexts_.begin(); EXPECT_FALSE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::none)); - io_service_.reset(); + io_service_.restart(); ASSERT_EQ(0u, io_service_.poll()); } } @@ -1460,10 +1460,10 @@ TEST_F(levin_notify, private_fluff_without_padding) auto context = contexts_.begin(); EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::fluff)); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); notifier.run_fluff(); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::fluff)); @@ -1513,10 +1513,10 @@ TEST_F(levin_notify, private_stem_without_padding) auto context = contexts_.begin(); EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::stem)); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); notifier.run_fluff(); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::stem)); @@ -1566,10 +1566,10 @@ TEST_F(levin_notify, private_local_without_padding) auto context = contexts_.begin(); EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::local)); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); notifier.run_fluff(); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::local)); @@ -1619,10 +1619,10 @@ TEST_F(levin_notify, private_forward_without_padding) auto context = contexts_.begin(); EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::forward)); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); notifier.run_fluff(); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::forward)); @@ -1672,7 +1672,7 @@ TEST_F(levin_notify, private_block_without_padding) auto context = contexts_.begin(); EXPECT_FALSE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::block)); - io_service_.reset(); + io_service_.restart(); ASSERT_EQ(0u, io_service_.poll()); } } @@ -1704,7 +1704,7 @@ TEST_F(levin_notify, private_none_without_padding) auto context = contexts_.begin(); EXPECT_FALSE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::none)); - io_service_.reset(); + io_service_.restart(); ASSERT_EQ(0u, io_service_.poll()); } } @@ -1735,10 +1735,10 @@ TEST_F(levin_notify, private_fluff_with_padding) auto context = contexts_.begin(); EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::fluff)); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); notifier.run_fluff(); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::fluff)); @@ -1787,10 +1787,10 @@ TEST_F(levin_notify, private_stem_with_padding) auto context = contexts_.begin(); EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::stem)); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); notifier.run_fluff(); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::stem)); @@ -1839,10 +1839,10 @@ TEST_F(levin_notify, private_local_with_padding) auto context = contexts_.begin(); EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::local)); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); notifier.run_fluff(); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::local)); @@ -1891,10 +1891,10 @@ TEST_F(levin_notify, private_forward_with_padding) auto context = contexts_.begin(); EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::forward)); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); notifier.run_fluff(); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::forward)); @@ -1943,7 +1943,7 @@ TEST_F(levin_notify, private_block_with_padding) auto context = contexts_.begin(); EXPECT_FALSE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::block)); - io_service_.reset(); + io_service_.restart(); ASSERT_EQ(0u, io_service_.poll()); } } @@ -1974,7 +1974,7 @@ TEST_F(levin_notify, private_none_with_padding) auto context = contexts_.begin(); EXPECT_FALSE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::none)); - io_service_.reset(); + io_service_.restart(); ASSERT_EQ(0u, io_service_.poll()); } } @@ -2008,14 +2008,14 @@ TEST_F(levin_notify, stem_mappings) auto context = contexts_.begin(); EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::stem)); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); if (events_.has_stem_txes()) break; EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::fluff)); notifier.run_fluff(); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); EXPECT_EQ(0u, context->process_send_queue()); @@ -2032,7 +2032,7 @@ TEST_F(levin_notify, stem_mappings) } notifier.run_epoch(); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); } EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::stem)); @@ -2070,7 +2070,7 @@ TEST_F(levin_notify, stem_mappings) auto& incoming = contexts_[i % contexts_.size()]; EXPECT_TRUE(notifier.send_txs(txs, incoming.get_id(), cryptonote::relay_method::stem)); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::stem)); @@ -2133,7 +2133,7 @@ TEST_F(levin_notify, fluff_multiple) auto context = contexts_.begin(); EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::stem)); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); if (!events_.has_stem_txes()) break; @@ -2164,12 +2164,12 @@ TEST_F(levin_notify, fluff_multiple) } notifier.run_epoch(); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); } EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::fluff)); notifier.run_fluff(); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); { auto context = contexts_.begin(); @@ -2192,10 +2192,10 @@ TEST_F(levin_notify, fluff_multiple) auto& incoming = contexts_[i % contexts_.size()]; EXPECT_TRUE(notifier.send_txs(txs, incoming.get_id(), cryptonote::relay_method::stem)); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); notifier.run_fluff(); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::fluff)); @@ -2252,7 +2252,7 @@ TEST_F(levin_notify, fluff_with_duplicate) auto context = contexts_.begin(); EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::fluff)); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); notifier.run_fluff(); ASSERT_LT(0u, io_service_.poll()); @@ -2303,7 +2303,7 @@ TEST_F(levin_notify, noise) } notifier.run_stems(); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); { std::size_t sent = 0; @@ -2316,7 +2316,7 @@ TEST_F(levin_notify, noise) EXPECT_TRUE(notifier.send_txs(txs, incoming_id, cryptonote::relay_method::local)); notifier.run_stems(); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::local)); @@ -2338,7 +2338,7 @@ TEST_F(levin_notify, noise) txs[0].resize(3000, 'r'); EXPECT_TRUE(notifier.send_txs(txs, incoming_id, cryptonote::relay_method::fluff)); notifier.run_stems(); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::fluff)); @@ -2352,7 +2352,7 @@ TEST_F(levin_notify, noise) } notifier.run_stems(); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); { std::size_t sent = 0; @@ -2397,7 +2397,7 @@ TEST_F(levin_notify, noise_stem) } notifier.run_stems(); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); { std::size_t sent = 0; @@ -2410,7 +2410,7 @@ TEST_F(levin_notify, noise_stem) EXPECT_TRUE(notifier.send_txs(txs, incoming_id, cryptonote::relay_method::stem)); notifier.run_stems(); - io_service_.reset(); + io_service_.restart(); ASSERT_LT(0u, io_service_.poll()); // downgraded to local when being notified diff --git a/tests/unit_tests/net.cpp b/tests/unit_tests/net.cpp index dc79f80a1..16ec7dd21 100644 --- a/tests/unit_tests/net.cpp +++ b/tests/unit_tests/net.cpp @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include #include @@ -972,8 +972,8 @@ namespace struct io_thread { - boost::asio::io_service io_service; - boost::asio::io_service::work work; + boost::asio::io_context io_service; + boost::asio::executor_work_guard work; stream_type::socket server; stream_type::acceptor acceptor; boost::thread io; @@ -981,7 +981,7 @@ namespace io_thread() : io_service(), - work(io_service), + work(io_service.get_executor()), server(io_service), acceptor(io_service), io([this] () { try { this->io_service.run(); } catch (const std::exception& e) { MERROR(e.what()); }}), @@ -1021,7 +1021,7 @@ namespace TEST(socks_client, unsupported_command) { - boost::asio::io_service io_service{}; + boost::asio::io_context io_service{}; stream_type::socket client{io_service}; auto test_client = net::socks::make_connect_client( @@ -1039,7 +1039,7 @@ TEST(socks_client, unsupported_command) TEST(socks_client, no_command) { - boost::asio::io_service io_service{}; + boost::asio::io_context io_service{}; stream_type::socket client{io_service}; auto test_client = net::socks::make_connect_client( @@ -1193,7 +1193,7 @@ TEST(socks_connector, host) { io_thread io{}; boost::asio::steady_timer timeout{io.io_service}; - timeout.expires_from_now(std::chrono::seconds{5}); + timeout.expires_after(std::chrono::seconds{5}); boost::unique_future sock = net::socks::connector{io.acceptor.local_endpoint()}("example.com", "8080", timeout); @@ -1220,7 +1220,7 @@ TEST(socks_connector, ipv4) { io_thread io{}; boost::asio::steady_timer timeout{io.io_service}; - timeout.expires_from_now(std::chrono::seconds{5}); + timeout.expires_after(std::chrono::seconds{5}); boost::unique_future sock = net::socks::connector{io.acceptor.local_endpoint()}("250.88.125.99", "8080", timeout); @@ -1246,7 +1246,7 @@ TEST(socks_connector, error) { io_thread io{}; boost::asio::steady_timer timeout{io.io_service}; - timeout.expires_from_now(std::chrono::seconds{5}); + timeout.expires_after(std::chrono::seconds{5}); boost::unique_future sock = net::socks::connector{io.acceptor.local_endpoint()}("250.88.125.99", "8080", timeout); @@ -1272,7 +1272,7 @@ TEST(socks_connector, timeout) { io_thread io{}; boost::asio::steady_timer timeout{io.io_service}; - timeout.expires_from_now(std::chrono::milliseconds{10}); + timeout.expires_after(std::chrono::milliseconds{10}); boost::unique_future sock = net::socks::connector{io.acceptor.local_endpoint()}("250.88.125.99", "8080", timeout); diff --git a/tests/unit_tests/node_server.cpp b/tests/unit_tests/node_server.cpp index 09b1d5461..e0a94beb5 100644 --- a/tests/unit_tests/node_server.cpp +++ b/tests/unit_tests/node_server.cpp @@ -438,14 +438,14 @@ TEST(cryptonote_protocol_handler, race_condition) using connections_t = std::vector; using shared_state_t = typename connection_t::shared_state; using shared_state_ptr = std::shared_ptr; - using io_context_t = boost::asio::io_service; + using io_context_t = boost::asio::io_context; using event_t = epee::simple_event; using ec_t = boost::system::error_code; auto create_conn_pair = [](connection_ptr in, connection_ptr out) { using endpoint_t = boost::asio::ip::tcp::endpoint; using acceptor_t = boost::asio::ip::tcp::acceptor; io_context_t io_context; - endpoint_t endpoint(boost::asio::ip::address::from_string("127.0.0.1"), 5262); + endpoint_t endpoint(boost::asio::ip::make_address("127.0.0.1"), 5262); acceptor_t acceptor(io_context); ec_t ec; acceptor.open(endpoint.protocol(), ec); @@ -453,7 +453,7 @@ TEST(cryptonote_protocol_handler, race_condition) acceptor.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true)); acceptor.bind(endpoint, ec); EXPECT_EQ(ec.value(), 0); - acceptor.listen(boost::asio::socket_base::max_connections, ec); + acceptor.listen(boost::asio::socket_base::max_listen_connections, ec); EXPECT_EQ(ec.value(), 0); out->socket().open(endpoint.protocol(), ec); EXPECT_EQ(ec.value(), 0); @@ -471,7 +471,7 @@ TEST(cryptonote_protocol_handler, race_condition) conn.get_context(context); return context.m_connection_id; }; - using work_t = boost::asio::io_service::work; + using work_t = boost::asio::executor_work_guard; using work_ptr = std::shared_ptr; using workers_t = std::vector; using commands_handler_t = epee::levin::levin_commands_handler; @@ -785,7 +785,7 @@ TEST(cryptonote_protocol_handler, race_condition) }; io_context_t io_context; - work_ptr work = std::make_shared(io_context); + work_ptr work = std::make_shared(io_context.get_executor()); workers_t workers; while (workers.size() < 4) { workers.emplace_back([&io_context]{ @@ -822,7 +822,7 @@ TEST(cryptonote_protocol_handler, race_condition) auto conn = connections.first; auto shared_state = daemon.main.shared_state; const auto tag = get_conn_tag(*conn); - conn->strand_.post([tag, conn, shared_state, &events]{ + boost::asio::post(conn->strand_, [tag, conn, shared_state, &events]{ shared_state->for_connection(tag, [](context_t &context){ context.m_expect_height = -1; context.m_expect_response = -1; @@ -849,10 +849,10 @@ TEST(cryptonote_protocol_handler, race_condition) events.check.raise(); events.finish.wait(); - connections.first->strand_.post([connections]{ + boost::asio::post(connections.first->strand_, [connections]{ connections.first->cancel(); }); - connections.second->strand_.post([connections]{ + boost::asio::post(connections.second->strand_, [connections]{ connections.second->cancel(); }); connections.first.reset(); @@ -896,7 +896,7 @@ TEST(cryptonote_protocol_handler, race_condition) work_ptr work; workers_t workers; } check; - check.work = std::make_shared(check.io_context); + check.work = std::make_shared(check.io_context.get_executor()); while (check.workers.size() < 2) { check.workers.emplace_back([&check]{ check.io_context.run(); @@ -917,7 +917,7 @@ TEST(cryptonote_protocol_handler, race_condition) auto conn = daemon.main.conn.back(); auto shared_state = daemon.main.shared_state; const auto tag = get_conn_tag(*conn); - conn->strand_.post([tag, conn, shared_state, &events]{ + boost::asio::post(conn->strand_, [tag, conn, shared_state, &events]{ shared_state->for_connection(tag, [](context_t &context){ EXPECT_TRUE(context.m_state == contexts::cryptonote::state_normal); return true; @@ -969,13 +969,13 @@ TEST(cryptonote_protocol_handler, race_condition) for (;daemon.main.conn.size(); daemon.main.conn.pop_back()) { auto conn = daemon.main.conn.back(); - conn->strand_.post([conn]{ + boost::asio::post(conn->strand_, [conn]{ conn->cancel(); }); } for (;daemon.alt.conn.size(); daemon.alt.conn.pop_back()) { auto conn = daemon.alt.conn.back(); - conn->strand_.post([conn]{ + boost::asio::post(conn->strand_, [conn]{ conn->cancel(); }); } @@ -1145,8 +1145,8 @@ TEST(node_server, race_condition) using connection_ptr = boost::shared_ptr; using shared_state_t = typename connection_t::shared_state; using shared_state_ptr = std::shared_ptr; - using io_context_t = boost::asio::io_service; - using work_t = boost::asio::io_service::work; + using io_context_t = boost::asio::io_context; + using work_t = boost::asio::executor_work_guard; using work_ptr = std::shared_ptr; using workers_t = std::vector; using endpoint_t = boost::asio::ip::tcp::endpoint; @@ -1163,23 +1163,23 @@ TEST(node_server, race_condition) static void destroy(epee::levin::levin_commands_handler* ptr) { delete ptr; } }; io_context_t io_context; - work_ptr work = std::make_shared(io_context); + work_ptr work = std::make_shared(io_context.get_executor()); workers_t workers; while (workers.size() < 4) { workers.emplace_back([&io_context]{ io_context.run(); }); } - io_context.post([&]{ + boost::asio::post(io_context, [&]{ protocol.on_idle(); }); - io_context.post([&]{ + boost::asio::post(io_context, [&]{ protocol.on_idle(); }); shared_state_ptr shared_state = std::make_shared(); shared_state->set_handler(new command_handler_t, &command_handler_t::destroy); connection_ptr conn{new connection_t(io_context, shared_state, {}, {})}; - endpoint_t endpoint(boost::asio::ip::address::from_string("127.0.0.1"), 48080); + endpoint_t endpoint(boost::asio::ip::make_address("127.0.0.1"), 48080); conn->socket().connect(endpoint); conn->socket().set_option(boost::asio::ip::tcp::socket::reuse_address(true)); conn->start({}, {}); @@ -1202,7 +1202,7 @@ TEST(node_server, race_condition) P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT ); handshaked.wait(); - conn->strand_.post([conn]{ + boost::asio::post(conn->strand_, [conn]{ conn->cancel(); }); conn.reset(); -- cgit v1.2.3