From 1f699fc3047de8145869a8db6d44b1bd0023ef1e Mon Sep 17 00:00:00 2001 From: eidheim Date: Thu, 13 Jun 2019 19:37:43 +0200 Subject: [PATCH] Related to #246 : added test where multiple clients sends posts concurrently to a server --- tests/io_test.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/io_test.cpp b/tests/io_test.cpp index 712481b..ebed11c 100644 --- a/tests/io_test.cpp +++ b/tests/io_test.cpp @@ -317,6 +317,27 @@ int main() { for(auto call : calls) ASSERT(call); } + + // Test concurrent requests from different clients + { + vector calls(10, 0); + vector threads; + for(size_t c = 0; c < 10; ++c) { + threads.emplace_back([c, &calls] { + HttpClient client("localhost:8080"); + client.request("POST", "/string", "A string", [c, &calls](shared_ptr response, const SimpleWeb::error_code &ec) { + ASSERT(!ec); + ASSERT(response->content.string() == "A string"); + calls[c] = 1; + }); + client.io_service->run(); + }); + } + for(auto &thread : threads) + thread.join(); + for(auto call : calls) + ASSERT(call); + } } // Test concurrent synchronous request calls