From 7ba067b7897687764a48ae3b96748eb5c4bfbbc7 Mon Sep 17 00:00:00 2001 From: ochafik Date: Fri, 4 Oct 2024 19:14:01 +0100 Subject: [PATCH] test is_alive alongside is_writable --- test/test.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/test.cc b/test/test.cc index 76c6f60..7875343 100644 --- a/test/test.cc +++ b/test/test.cc @@ -165,9 +165,11 @@ TEST(SocketStream, is_writable_UNIX) { }; asSocketStream(fds[0], [&](Stream &s0) { EXPECT_EQ(s0.socket(), fds[0]); + EXPECT_TRUE(s0.is_alive()); EXPECT_TRUE(s0.is_writable()); EXPECT_EQ(0, close(fds[1])); + EXPECT_FALSE(s0.is_alive()); EXPECT_FALSE(s0.is_writable()); return true; @@ -209,6 +211,7 @@ TEST(SocketStream, is_writable_INET) { }; asSocketStream(disconnected_svr_sock, [&](Stream &ss) { EXPECT_EQ(ss.socket(), disconnected_svr_sock); + EXPECT_FALSE(ss.is_alive()); EXPECT_FALSE(ss.is_writable()); return true; @@ -5456,14 +5459,16 @@ TEST(LongPollingTest, ClientCloseDetection) { svr.Get("/events", [&](const Request & /*req*/, Response &res) { res.set_chunked_content_provider( "text/plain", [](std::size_t const, DataSink &sink) -> bool { - EXPECT_TRUE(sink.is_writable()); // the socket is alive + EXPECT_TRUE(sink.is_alive()); + EXPECT_TRUE(sink.is_writable()); sink.os << "hello"; auto count = 10; - while (count > 0 && sink.is_writable()) { + while (count > 0 && sink.is_writable() && sink.is_alive()) { this_thread::sleep_for(chrono::milliseconds(10)); } - EXPECT_FALSE(sink.is_writable()); // the socket is closed + EXPECT_FALSE(sink.is_alive()); + EXPECT_FALSE(sink.is_writable()); return true; }); });