Skip to content

Commit

Permalink
ASSERTS
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Apr 18, 2024
1 parent 4151266 commit efcc43e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions nano/core_test/asio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ TEST (asio, multithreaded_context)
std::atomic<size_t> read_counter{ 0 };

auto reader_coro = [&] (asio::ip::tcp::socket socket) -> asio::awaitable<void> {
debug_assert (strand.running_in_this_thread ());

std::cout << "reader started" << std::endl;

while (true)
{
std::array<uint8_t, 1024> buffer;
debug_assert (strand.running_in_this_thread ());
auto size = co_await socket.async_read_some (asio::buffer (buffer), asio::use_awaitable);
read_counter += size;
}
Expand All @@ -55,10 +58,13 @@ TEST (asio, multithreaded_context)
std::vector<reader> readers;

auto acceptor_coro = [&] (asio::ip::tcp::acceptor & acceptor) -> asio::awaitable<void> {
debug_assert (strand.running_in_this_thread ());

std::cout << "listening started" << std::endl;

while (true)
{
debug_assert (strand.running_in_this_thread ());
auto socket = co_await acceptor.async_accept (asio::use_awaitable);

std::cout << "accepted connection" << std::endl;
Expand All @@ -76,6 +82,8 @@ TEST (asio, multithreaded_context)
auto acceptor_fut = asio::co_spawn (strand, acceptor_coro (acceptor), asio::use_future);

auto sender_coro = [&] () -> asio::awaitable<void> {
debug_assert (strand.running_in_this_thread ());

std::cout << "sender started" << std::endl;

asio::ip::tcp::socket socket{ strand };
Expand All @@ -84,6 +92,7 @@ TEST (asio, multithreaded_context)
std::array<uint8_t, 1024> buffer;
while (true)
{
debug_assert (strand.running_in_this_thread ());
co_await socket.async_write_some (asio::buffer (buffer), asio::use_awaitable);
}
};
Expand Down

0 comments on commit efcc43e

Please sign in to comment.