Skip to content

Commit fd324e1

Browse files
committed
Add KeepAliveTest.MaxCount
1 parent 366eda7 commit fd324e1

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

test/test.cc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5732,6 +5732,41 @@ TEST(KeepAliveTest, ReadTimeout) {
57325732
EXPECT_EQ("b", resb->body);
57335733
}
57345734

5735+
TEST(KeepAliveTest, MaxCount) {
5736+
size_t keep_alive_max_count = 3;
5737+
5738+
Server svr;
5739+
svr.set_keep_alive_max_count(keep_alive_max_count);
5740+
5741+
svr.Get("/hi", [](const httplib::Request &, httplib::Response &res) {
5742+
res.set_content("Hello World!", "text/plain");
5743+
});
5744+
5745+
auto listen_thread = std::thread([&svr] { svr.listen(HOST, PORT); });
5746+
auto se = detail::scope_exit([&] {
5747+
svr.stop();
5748+
listen_thread.join();
5749+
ASSERT_FALSE(svr.is_running());
5750+
});
5751+
5752+
svr.wait_until_ready();
5753+
5754+
Client cli(HOST, PORT);
5755+
cli.set_keep_alive(true);
5756+
5757+
for (size_t i = 0; i < 5; i++) {
5758+
auto result = cli.Get("/hi");
5759+
ASSERT_TRUE(result);
5760+
EXPECT_EQ(StatusCode::OK_200, result->status);
5761+
5762+
if (i == keep_alive_max_count - 1) {
5763+
EXPECT_EQ("close", result->get_header_value("Connection"));
5764+
} else {
5765+
EXPECT_FALSE(result->has_header("Connection"));
5766+
}
5767+
}
5768+
}
5769+
57355770
TEST(KeepAliveTest, Issue1041) {
57365771
Server svr;
57375772
svr.set_keep_alive_timeout(3);

0 commit comments

Comments
 (0)