From 55530cf1ec110c1300b8587f002c413d9cfd64f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Mon, 18 Nov 2024 23:14:15 +0100 Subject: [PATCH] Test fixing --- nano/core_test/socket.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/nano/core_test/socket.cpp b/nano/core_test/socket.cpp index b0260bbb8..5c72b4857 100644 --- a/nano/core_test/socket.cpp +++ b/nano/core_test/socket.cpp @@ -374,6 +374,9 @@ TEST (socket_timeout, read) TEST (socket_timeout, write) { + std::atomic done = false; + std::atomic ec; + // create one node and set timeout to 1 second nano::test::system system (1); std::shared_ptr node = system.nodes[0]; @@ -396,8 +399,7 @@ TEST (socket_timeout, write) // eventually, the all tcp queues should fill up and async_write will not be able to progress // and the timeout should kick in and close the socket, which will cause the async_write to return an error auto socket = std::make_shared (*node, nano::transport::socket_endpoint::client); // socket with a max queue size much larger than OS buffers - std::atomic done = false; - boost::system::error_code ec; + socket->async_connect (acceptor.local_endpoint (), [&socket, &ec, &done] (boost::system::error_code const & ec_a) { EXPECT_FALSE (ec_a); @@ -407,8 +409,8 @@ TEST (socket_timeout, write) socket->async_write (nano::shared_const_buffer{ buffer }, [&ec, &done] (boost::system::error_code const & ec_a, size_t size_a) { if (ec_a) { - ec = ec_a; done = true; + ec = ec_a; } }); } @@ -416,7 +418,7 @@ TEST (socket_timeout, write) // check that the callback was called and we got an error ASSERT_TIMELY_EQ (10s, done, true); - ASSERT_TRUE (ec); + ASSERT_TRUE (ec.load ()); ASSERT_EQ (1, node->stats.count (nano::stat::type::tcp, nano::stat::detail::tcp_write_error, nano::stat::dir::in)); // check that the socket was closed due to tcp_io_timeout timeout @@ -483,6 +485,9 @@ TEST (socket_timeout, read_overlapped) TEST (socket_timeout, write_overlapped) { + std::atomic done = false; + std::atomic ec; + // create one node and set timeout to 1 second nano::test::system system (1); std::shared_ptr node = system.nodes[0]; @@ -510,8 +515,6 @@ TEST (socket_timeout, write_overlapped) // eventually, the all tcp queues should fill up and async_write will not be able to progress // and the timeout should kick in and close the socket, which will cause the async_write to return an error auto socket = std::make_shared (*node, nano::transport::socket_endpoint::client); // socket with a max queue size much larger than OS buffers - std::atomic done = false; - boost::system::error_code ec; socket->async_connect (acceptor.local_endpoint (), [&socket, &ec, &done] (boost::system::error_code const & ec_a) { EXPECT_FALSE (ec_a); @@ -525,8 +528,8 @@ TEST (socket_timeout, write_overlapped) socket->async_write (nano::shared_const_buffer{ buffer2 }, [&ec, &done] (boost::system::error_code const & ec_a, size_t size_a) { if (ec_a) { - ec = ec_a; done = true; + ec = ec_a; } }); } @@ -534,7 +537,7 @@ TEST (socket_timeout, write_overlapped) // check that the callback was called and we got an error ASSERT_TIMELY_EQ (10s, done, true); - ASSERT_TRUE (ec); + ASSERT_TRUE (ec.load ()); ASSERT_EQ (1, node->stats.count (nano::stat::type::tcp, nano::stat::detail::tcp_write_error, nano::stat::dir::in)); // check that the socket was closed due to tcp_io_timeout timeout