- 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"
|
||||
|
||||
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;
|
||||
auto reqSpec = (payload.empty() ? client.get(url) : client.post(url));
|
||||
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);
|
||||
barrier.wait_for(std::chrono::seconds(2));
|
||||
client.shutdown();
|
||||
if (error) {
|
||||
throw std::runtime_error(msg);
|
||||
}
|
||||
@@ -52,23 +55,19 @@ TEST_CASE("Server Basic Endpoints", "[server_basic]") {
|
||||
const size_t nDAGRunners = 10,
|
||||
nWebThreads = 10;
|
||||
|
||||
daggy::Server server(listenSpec, logger, executor, 10);
|
||||
daggy::Server server(listenSpec, logger, executor, nDAGRunners);
|
||||
server.init(nWebThreads);
|
||||
server.start();
|
||||
|
||||
Pistache::Http::Experimental::Client client;
|
||||
const std::string host = "localhost:";
|
||||
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);
|
||||
}
|
||||
|
||||
SECTION("dag submission") {
|
||||
// submit a DAGRun
|
||||
std::string dagRun = R"({
|
||||
std::string dagRun = R"({
|
||||
"name": "unit_server",
|
||||
"parameters": { "DIRS": [ "A", "B" ] },
|
||||
"tasks": [
|
||||
@@ -81,13 +80,12 @@ TEST_CASE("Server Basic Endpoints", "[server_basic]") {
|
||||
"parents": [ "touch" ]
|
||||
}
|
||||
]
|
||||
}
|
||||
)";
|
||||
})";
|
||||
|
||||
auto response = REQUEST(client, baseURL + "/v1/dagrun/", dagRun);
|
||||
{
|
||||
auto response = REQUEST(baseURL + "/v1/dagrun/", dagRun);
|
||||
REQUIRE(response.code() == Pistache::Http::Code::Ok);
|
||||
}
|
||||
|
||||
server.shutdown();
|
||||
client.shutdown();
|
||||
}
|
||||
Reference in New Issue
Block a user