|
33 | 33 | #include <netinet/in.h> |
34 | 34 | #include <sys/socket.h> |
35 | 35 | #include "httpserver.hpp" |
| 36 | +#include <thread> |
36 | 37 |
|
37 | 38 | using namespace std; |
38 | 39 | using namespace httpserver; |
@@ -426,6 +427,36 @@ LT_BEGIN_AUTO_TEST(ws_start_stop_suite, ssl_with_trust) |
426 | 427 | ws.stop(); |
427 | 428 | LT_END_AUTO_TEST(ssl_with_trust) |
428 | 429 |
|
| 430 | +void start_ws_blocking(webserver* ws) |
| 431 | +{ |
| 432 | + ok_resource* ok = new ok_resource(); |
| 433 | + ws->register_resource("base", ok); |
| 434 | + ws->start(true); |
| 435 | +} |
| 436 | + |
| 437 | +LT_BEGIN_AUTO_TEST(ws_start_stop_suite, blocking_server) |
| 438 | + webserver ws = create_webserver(8080); |
| 439 | + std::thread server(start_ws_blocking, &ws); |
| 440 | + |
| 441 | + curl_global_init(CURL_GLOBAL_ALL); |
| 442 | + std::string s; |
| 443 | + CURL *curl = curl_easy_init(); |
| 444 | + CURLcode res; |
| 445 | + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); // avoid verifying ssl |
| 446 | + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); // avoid verifying ssl |
| 447 | + curl_easy_setopt(curl, CURLOPT_URL, "localhost:8080/base"); |
| 448 | + curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); |
| 449 | + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc); |
| 450 | + curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s); |
| 451 | + res = curl_easy_perform(curl); |
| 452 | + LT_ASSERT_EQ(res, 0); |
| 453 | + LT_CHECK_EQ(s, "OK"); |
| 454 | + curl_easy_cleanup(curl); |
| 455 | + |
| 456 | + ws.stop(); |
| 457 | + server.join(); |
| 458 | +LT_END_AUTO_TEST(blocking_server) |
| 459 | + |
429 | 460 | LT_BEGIN_AUTO_TEST_ENV() |
430 | 461 | AUTORUN_TESTS() |
431 | 462 | LT_END_AUTO_TEST_ENV() |
0 commit comments