@@ -2720,6 +2720,43 @@ TEST(ExceptionTest, ThrowExceptionInHandler) {
27202720 ASSERT_FALSE (svr.is_running ());
27212721}
27222722
2723+ TEST (KeepAliveTest, ReadTimeout) {
2724+ Server svr;
2725+
2726+ svr.Get (" /a" , [&](const Request & /* req*/ , Response &res) {
2727+ std::this_thread::sleep_for (std::chrono::seconds (2 ));
2728+ res.set_content (" a" , " text/plain" );
2729+ });
2730+
2731+ svr.Get (" /b" , [&](const Request & /* req*/ , Response &res) {
2732+ res.set_content (" b" , " text/plain" );
2733+ });
2734+
2735+ auto listen_thread = std::thread ([&svr]() { svr.listen (" localhost" , PORT); });
2736+ while (!svr.is_running ()) {
2737+ std::this_thread::sleep_for (std::chrono::milliseconds (1 ));
2738+ }
2739+
2740+ // Give GET time to get a few messages.
2741+ std::this_thread::sleep_for (std::chrono::seconds (1 ));
2742+
2743+ Client cli (" localhost" , PORT);
2744+ cli.set_keep_alive (true );
2745+ cli.set_read_timeout (1 );
2746+
2747+ auto resa = cli.Get (" /a" );
2748+ ASSERT_TRUE (resa == nullptr );
2749+
2750+ auto resb = cli.Get (" /b" );
2751+ ASSERT_TRUE (resb != nullptr );
2752+ EXPECT_EQ (200 , resb->status );
2753+ EXPECT_EQ (" b" , resb->body );
2754+
2755+ svr.stop ();
2756+ listen_thread.join ();
2757+ ASSERT_FALSE (svr.is_running ());
2758+ }
2759+
27232760class ServerTestWithAI_PASSIVE : public ::testing::Test {
27242761protected:
27252762 ServerTestWithAI_PASSIVE ()
0 commit comments