diff --git a/tests/test_server.cpp b/tests/test_server.cpp index e5d9dce..02230c3 100644 --- a/tests/test_server.cpp +++ b/tests/test_server.cpp @@ -61,6 +61,7 @@ struct ShutdownTestHandler : ConnectionHandler { std::span reply; WeakRef wconn; std::latch received_data{1}; + std::latch connection_closed_latch{1}; ConnectionShutdown shutdown_mode = ConnectionShutdown::None; std::atomic connection_closed{false}; @@ -71,7 +72,10 @@ struct ShutdownTestHandler : ConnectionHandler { received_data.count_down(); } - void on_connection_closed(Connection &) override { connection_closed = true; } + void on_connection_closed(Connection &) override { + connection_closed = true; + connection_closed_latch.count_down(); + } }; TEST_CASE("Connection shutdown write-only mode") { @@ -159,9 +163,9 @@ TEST_CASE("Connection shutdown full mode") { int close_result = read(fd, extra_buf, 1); CHECK(close_result == 0); // EOF indicates connection was closed - // The blocking read already synchronized - connection is definitely closed - CHECK(handler.connection_closed.load() == - true); // Connection should be closed + // Wait for connection closed callback to be called + handler.connection_closed_latch.wait(); + CHECK(handler.connection_closed.load() == true); close(fd); server->shutdown();