Skip to content

Commit

Permalink
Join threads in socket tests (#2009)
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptocode authored May 21, 2019
1 parent 24734f6 commit ca91fa1
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions nano/core_test/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,19 @@ TEST (socket, concurrent_writes)

// Execute overlapping writes from multiple threads
auto client (clients[0]);
std::vector<std::thread> 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<std::vector<uint8_t>> ());
buff->push_back ('A' + i);
client->async_write (buff);
}
});
runner.detach ();
}

ASSERT_FALSE (read_count_completion.await_count_for (10s));
Expand All @@ -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 ();
}
}

0 comments on commit ca91fa1

Please # to comment.