From 2fd368a643813165fb817fc957fd8e880fa6fca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Wed, 27 Mar 2024 18:50:24 +0100 Subject: [PATCH] Make socket tests pass --- nano/core_test/socket.cpp | 42 ++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/nano/core_test/socket.cpp b/nano/core_test/socket.cpp index 680e8ef259..85d8211791 100644 --- a/nano/core_test/socket.cpp +++ b/nano/core_test/socket.cpp @@ -31,8 +31,11 @@ TEST (socket, max_connections) // start a server socket that allows max 2 live connections auto listener = std::make_shared (server_port, *node, 2); nano::test::stop_guard stop_guard{ *listener }; - listener->start ([&server_sockets] (std::shared_ptr const & new_connection, boost::system::error_code const & ec_a) { - server_sockets.push_back (new_connection); + listener->start ([&server_sockets] (std::shared_ptr const & new_connection, boost::system::error_code const & ec) { + if (!ec) + { + server_sockets.push_back (new_connection); + } return true; }); @@ -124,8 +127,11 @@ TEST (socket, max_connections_per_ip) auto listener = std::make_shared (server_port, *node, max_global_connections); nano::test::stop_guard stop_guard{ *listener }; - listener->start ([&server_sockets] (std::shared_ptr const & new_connection, boost::system::error_code const & ec_a) { - server_sockets.push_back (new_connection); + listener->start ([&server_sockets] (std::shared_ptr const & new_connection, boost::system::error_code const & ec) { + if (!ec) + { + server_sockets.push_back (new_connection); + } return true; }); @@ -243,8 +249,11 @@ TEST (socket, max_connections_per_subnetwork) auto listener = std::make_shared (server_port, *node, max_global_connections); nano::test::stop_guard stop_guard{ *listener }; - listener->start ([&server_sockets] (std::shared_ptr const & new_connection, boost::system::error_code const & ec_a) { - server_sockets.push_back (new_connection); + listener->start ([&server_sockets] (std::shared_ptr const & new_connection, boost::system::error_code const & ec) { + if (!ec) + { + server_sockets.push_back (new_connection); + } return true; }); @@ -302,8 +311,11 @@ TEST (socket, disabled_max_peers_per_ip) auto server_socket = std::make_shared (server_port, *node, max_global_connections); nano::test::stop_guard stop_guard{ *server_socket }; - server_socket->start ([&server_sockets] (std::shared_ptr const & new_connection, boost::system::error_code const & ec_a) { - server_sockets.push_back (new_connection); + server_socket->start ([&server_sockets] (std::shared_ptr const & new_connection, boost::system::error_code const & ec) { + if (!ec) + { + server_sockets.push_back (new_connection); + } return true; }); @@ -361,8 +373,11 @@ TEST (socket, disconnection_of_silent_connections) // start a server listening socket auto listener = std::make_shared (server_port, *node, 1); nano::test::stop_guard stop_guard{ *listener }; - listener->start ([&server_data_socket] (std::shared_ptr const & new_connection, boost::system::error_code const & ec_a) { - server_data_socket = new_connection; + listener->start ([&server_data_socket] (std::shared_ptr const & new_connection, boost::system::error_code const & ec) { + if (!ec) + { + server_data_socket = new_connection; + } return true; }); @@ -411,8 +426,11 @@ TEST (socket, drop_policy) auto listener = std::make_shared (server_port, *node, 1); nano::test::stop_guard stop_guard{ *listener }; - listener->start ([&connections] (std::shared_ptr const & new_connection, boost::system::error_code const & ec_a) { - connections.push_back (new_connection); + listener->start ([&connections] (std::shared_ptr const & new_connection, boost::system::error_code const & ec) { + if (!ec) + { + connections.push_back (new_connection); + } return true; });