- Fixing request logic to avoid hangs when REQUIREs fail before the client has been shutdown.
This commit is contained in:
@@ -10,7 +10,9 @@
|
|||||||
#include "daggy/loggers/dag_run/OStreamLogger.hpp"
|
#include "daggy/loggers/dag_run/OStreamLogger.hpp"
|
||||||
|
|
||||||
Pistache::Http::Response
|
Pistache::Http::Response
|
||||||
REQUEST(Pistache::Http::Experimental::Client &client, std::string url, std::string payload = "") {
|
REQUEST(std::string url, std::string payload = "") {
|
||||||
|
Pistache::Http::Experimental::Client client;
|
||||||
|
client.init();
|
||||||
Pistache::Http::Response response;
|
Pistache::Http::Response response;
|
||||||
auto reqSpec = (payload.empty() ? client.get(url) : client.post(url));
|
auto reqSpec = (payload.empty() ? client.get(url) : client.post(url));
|
||||||
reqSpec.timeout(std::chrono::seconds(2));
|
reqSpec.timeout(std::chrono::seconds(2));
|
||||||
@@ -37,6 +39,7 @@ REQUEST(Pistache::Http::Experimental::Client &client, std::string url, std::stri
|
|||||||
|
|
||||||
Pistache::Async::Barrier<Pistache::Http::Response> barrier(request);
|
Pistache::Async::Barrier<Pistache::Http::Response> barrier(request);
|
||||||
barrier.wait_for(std::chrono::seconds(2));
|
barrier.wait_for(std::chrono::seconds(2));
|
||||||
|
client.shutdown();
|
||||||
if (error) {
|
if (error) {
|
||||||
throw std::runtime_error(msg);
|
throw std::runtime_error(msg);
|
||||||
}
|
}
|
||||||
@@ -52,23 +55,19 @@ TEST_CASE("Server Basic Endpoints", "[server_basic]") {
|
|||||||
const size_t nDAGRunners = 10,
|
const size_t nDAGRunners = 10,
|
||||||
nWebThreads = 10;
|
nWebThreads = 10;
|
||||||
|
|
||||||
daggy::Server server(listenSpec, logger, executor, 10);
|
daggy::Server server(listenSpec, logger, executor, nDAGRunners);
|
||||||
server.init(nWebThreads);
|
server.init(nWebThreads);
|
||||||
server.start();
|
server.start();
|
||||||
|
|
||||||
Pistache::Http::Experimental::Client client;
|
|
||||||
const std::string host = "localhost:";
|
const std::string host = "localhost:";
|
||||||
const std::string baseURL = host + std::to_string(server.getPort());
|
const std::string baseURL = host + std::to_string(server.getPort());
|
||||||
client.init();
|
|
||||||
|
|
||||||
SECTION("/ready endpoint") {
|
{
|
||||||
auto response = REQUEST(client, baseURL + "/ready");
|
auto response = REQUEST(baseURL + "/ready");
|
||||||
REQUIRE(response.code() == Pistache::Http::Code::Ok);
|
REQUIRE(response.code() == Pistache::Http::Code::Ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("dag submission") {
|
std::string dagRun = R"({
|
||||||
// submit a DAGRun
|
|
||||||
std::string dagRun = R"({
|
|
||||||
"name": "unit_server",
|
"name": "unit_server",
|
||||||
"parameters": { "DIRS": [ "A", "B" ] },
|
"parameters": { "DIRS": [ "A", "B" ] },
|
||||||
"tasks": [
|
"tasks": [
|
||||||
@@ -81,13 +80,12 @@ TEST_CASE("Server Basic Endpoints", "[server_basic]") {
|
|||||||
"parents": [ "touch" ]
|
"parents": [ "touch" ]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
})";
|
||||||
)";
|
|
||||||
|
|
||||||
auto response = REQUEST(client, baseURL + "/v1/dagrun/", dagRun);
|
{
|
||||||
|
auto response = REQUEST(baseURL + "/v1/dagrun/", dagRun);
|
||||||
REQUIRE(response.code() == Pistache::Http::Code::Ok);
|
REQUIRE(response.code() == Pistache::Http::Code::Ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
server.shutdown();
|
server.shutdown();
|
||||||
client.shutdown();
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user