Skip to content

Commit

Permalink
Make socket tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Mar 27, 2024
1 parent 3ea2f5c commit 2fd368a
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions nano/core_test/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ TEST (socket, max_connections)
// start a server socket that allows max 2 live connections
auto listener = std::make_shared<nano::transport::tcp_listener> (server_port, *node, 2);
nano::test::stop_guard stop_guard{ *listener };
listener->start ([&server_sockets] (std::shared_ptr<nano::transport::socket> const & new_connection, boost::system::error_code const & ec_a) {
server_sockets.push_back (new_connection);
listener->start ([&server_sockets] (std::shared_ptr<nano::transport::socket> const & new_connection, boost::system::error_code const & ec) {
if (!ec)
{
server_sockets.push_back (new_connection);
}
return true;
});

Expand Down Expand Up @@ -124,8 +127,11 @@ TEST (socket, max_connections_per_ip)

auto listener = std::make_shared<nano::transport::tcp_listener> (server_port, *node, max_global_connections);
nano::test::stop_guard stop_guard{ *listener };
listener->start ([&server_sockets] (std::shared_ptr<nano::transport::socket> const & new_connection, boost::system::error_code const & ec_a) {
server_sockets.push_back (new_connection);
listener->start ([&server_sockets] (std::shared_ptr<nano::transport::socket> const & new_connection, boost::system::error_code const & ec) {
if (!ec)
{
server_sockets.push_back (new_connection);
}
return true;
});

Expand Down Expand Up @@ -243,8 +249,11 @@ TEST (socket, max_connections_per_subnetwork)

auto listener = std::make_shared<nano::transport::tcp_listener> (server_port, *node, max_global_connections);
nano::test::stop_guard stop_guard{ *listener };
listener->start ([&server_sockets] (std::shared_ptr<nano::transport::socket> const & new_connection, boost::system::error_code const & ec_a) {
server_sockets.push_back (new_connection);
listener->start ([&server_sockets] (std::shared_ptr<nano::transport::socket> const & new_connection, boost::system::error_code const & ec) {
if (!ec)
{
server_sockets.push_back (new_connection);
}
return true;
});

Expand Down Expand Up @@ -302,8 +311,11 @@ TEST (socket, disabled_max_peers_per_ip)

auto server_socket = std::make_shared<nano::transport::tcp_listener> (server_port, *node, max_global_connections);
nano::test::stop_guard stop_guard{ *server_socket };
server_socket->start ([&server_sockets] (std::shared_ptr<nano::transport::socket> const & new_connection, boost::system::error_code const & ec_a) {
server_sockets.push_back (new_connection);
server_socket->start ([&server_sockets] (std::shared_ptr<nano::transport::socket> const & new_connection, boost::system::error_code const & ec) {
if (!ec)
{
server_sockets.push_back (new_connection);
}
return true;
});

Expand Down Expand Up @@ -361,8 +373,11 @@ TEST (socket, disconnection_of_silent_connections)
// start a server listening socket
auto listener = std::make_shared<nano::transport::tcp_listener> (server_port, *node, 1);
nano::test::stop_guard stop_guard{ *listener };
listener->start ([&server_data_socket] (std::shared_ptr<nano::transport::socket> const & new_connection, boost::system::error_code const & ec_a) {
server_data_socket = new_connection;
listener->start ([&server_data_socket] (std::shared_ptr<nano::transport::socket> const & new_connection, boost::system::error_code const & ec) {
if (!ec)
{
server_data_socket = new_connection;
}
return true;
});

Expand Down Expand Up @@ -411,8 +426,11 @@ TEST (socket, drop_policy)

auto listener = std::make_shared<nano::transport::tcp_listener> (server_port, *node, 1);
nano::test::stop_guard stop_guard{ *listener };
listener->start ([&connections] (std::shared_ptr<nano::transport::socket> const & new_connection, boost::system::error_code const & ec_a) {
connections.push_back (new_connection);
listener->start ([&connections] (std::shared_ptr<nano::transport::socket> const & new_connection, boost::system::error_code const & ec) {
if (!ec)
{
connections.push_back (new_connection);
}
return true;
});

Expand Down

0 comments on commit 2fd368a

Please sign in to comment.