From ca91fa14a0b36feac851d2dd742ee3d5abd776fc Mon Sep 17 00:00:00 2001 From: cryptocode Date: Tue, 21 May 2019 21:40:21 +0200 Subject: [PATCH] Join threads in socket tests (#2009) --- nano/core_test/socket.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/nano/core_test/socket.cpp b/nano/core_test/socket.cpp index 667836c1e..b097299a6 100644 --- a/nano/core_test/socket.cpp +++ b/nano/core_test/socket.cpp @@ -85,11 +85,12 @@ TEST (socket, concurrent_writes) // Execute overlapping writes from multiple threads auto client (clients[0]); + std::vector client_threads; for (int i = 0; i < client_count; i++) { // Note: this gives a warning on most compilers because message_count is constexpr and a // capture isn't needed. However, removing it fails to compile on VS2017 due to a known compiler bug. - std::thread runner ([&client, &message_count]() { + client_threads.emplace_back ([&client, &message_count]() { for (int i = 0; i < message_count; i++) { auto buff (std::make_shared> ()); @@ -97,7 +98,6 @@ TEST (socket, concurrent_writes) client->async_write (buff); } }); - runner.detach (); } ASSERT_FALSE (read_count_completion.await_count_for (10s)); @@ -108,4 +108,9 @@ TEST (socket, concurrent_writes) ASSERT_EQ (node->stats.count (nano::stat::type::tcp, nano::stat::detail::tcp_accept_success, nano::stat::dir::in), client_count); // We may exhaust max connections and have some tcp accept failures, but no more than the client count ASSERT_LT (node->stats.count (nano::stat::type::tcp, nano::stat::detail::tcp_accept_failure, nano::stat::dir::in), client_count); + + for (auto & t : client_threads) + { + t.join (); + } }