Fix flaky connection shutdown test

This commit is contained in:
2025-09-15 21:39:48 -04:00
parent 5e625197aa
commit 4ecbc07367

View File

@@ -61,6 +61,7 @@ struct ShutdownTestHandler : ConnectionHandler {
std::span<std::string_view> reply; std::span<std::string_view> reply;
WeakRef<MessageSender> wconn; WeakRef<MessageSender> wconn;
std::latch received_data{1}; std::latch received_data{1};
std::latch connection_closed_latch{1};
ConnectionShutdown shutdown_mode = ConnectionShutdown::None; ConnectionShutdown shutdown_mode = ConnectionShutdown::None;
std::atomic<bool> connection_closed{false}; std::atomic<bool> connection_closed{false};
@@ -71,7 +72,10 @@ struct ShutdownTestHandler : ConnectionHandler {
received_data.count_down(); 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") { 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); int close_result = read(fd, extra_buf, 1);
CHECK(close_result == 0); // EOF indicates connection was closed CHECK(close_result == 0); // EOF indicates connection was closed
// The blocking read already synchronized - connection is definitely closed // Wait for connection closed callback to be called
CHECK(handler.connection_closed.load() == handler.connection_closed_latch.wait();
true); // Connection should be closed CHECK(handler.connection_closed.load() == true);
close(fd); close(fd);
server->shutdown(); server->shutdown();