From 6ee8bd992e6719d3cba7a0dba15602ea7060f022 Mon Sep 17 00:00:00 2001 From: ipknHama Date: Sun, 14 Sep 2014 08:16:49 +0900 Subject: added test case for handling repeated request wrong --- tests/unittest.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'tests') diff --git a/tests/unittest.cpp b/tests/unittest.cpp index 41387fa..b552ddc 100644 --- a/tests/unittest.cpp +++ b/tests/unittest.cpp @@ -717,6 +717,44 @@ TEST(middleware_cookieparser) server.stop(); } +TEST(bug_quick_repeated_request) +{ + static char buf[2048]; + + SimpleApp app; + + CROW_ROUTE(app, "/")([&]{ + return "hello"; + }); + + decltype(app)::server_t server(&app, 45451); + auto _ = async(launch::async, [&]{server.run();}); + std::string sendmsg = "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n"; + asio::io_service is; + { + std::vector> v; + for(int i = 0; i < 5; i++) + { + v.push_back(async(launch::async, + [&] + { + asio::ip::tcp::socket c(is); + c.connect(asio::ip::tcp::endpoint(asio::ip::address::from_string("127.0.0.1"), 45451)); + + for(int j = 0; j < 5; j ++) + { + c.send(asio::buffer(sendmsg)); + + size_t received = c.receive(asio::buffer(buf, 2048)); + ASSERT_EQUAL("hello", std::string(buf + received - 5, buf + received)); + } + c.close(); + })); + } + } + server.stop(); +} + int main() { return testmain(); -- cgit v1.2.3-54-g00ecf