This commit is contained in:
eidheim 2019-06-14 20:14:56 +02:00
commit 45d39e3c18
6 changed files with 163 additions and 99 deletions

View file

@ -4,10 +4,6 @@
using namespace std;
#ifndef USE_STANDALONE_ASIO
namespace asio = boost::asio;
#endif
using HttpServer = SimpleWeb::Server<SimpleWeb::HTTP>;
using HttpClient = SimpleWeb::Client<SimpleWeb::HTTP>;
@ -315,12 +311,33 @@ int main() {
for(auto &thread : threads)
thread.join();
ASSERT(client.connections.size() == 100);
client.io_service->reset();
SimpleWeb::restart(*client.io_service);
client.io_service->run();
ASSERT(client.connections.size() == 1);
for(auto call : calls)
ASSERT(call);
}
// Test concurrent requests from different clients
{
vector<int> calls(10, 0);
vector<thread> 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<HttpClient::Response> 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
@ -390,7 +407,7 @@ int main() {
// Test Client client's stop()
for(size_t c = 0; c < 40; ++c) {
auto io_service = make_shared<asio::io_service>();
auto io_service = make_shared<SimpleWeb::io_context>();
bool call = false;
HttpClient client("localhost:8080");
client.io_service = io_service;
@ -410,7 +427,7 @@ int main() {
// Test Client destructor that should cancel the client's request
for(size_t c = 0; c < 40; ++c) {
auto io_service = make_shared<asio::io_service>();
auto io_service = make_shared<SimpleWeb::io_context>();
{
HttpClient client("localhost:8080");
client.io_service = io_service;
@ -431,7 +448,7 @@ int main() {
// Test server destructor
{
auto io_service = make_shared<asio::io_service>();
auto io_service = make_shared<SimpleWeb::io_context>();
bool call = false;
bool client_catch = false;
{

View file

@ -147,7 +147,7 @@ int main() {
ASSERT(fields_result1 == fields_result2 && fields_result1 == fields);
auto serverTest = make_shared<ServerTest>();
serverTest->io_service = std::make_shared<asio::io_service>();
serverTest->io_service = std::make_shared<io_context>();
serverTest->parse_request_test();
@ -160,7 +160,7 @@ int main() {
clientTest2->parse_response_header_test();
asio::io_service io_service;
io_context io_service;
asio::ip::tcp::socket socket(io_service);
SimpleWeb::Server<HTTP>::Request request(static_cast<size_t>(-1), nullptr);
{