Fixing test cases on daggyr for new polling

This commit is contained in:
Ian Roddis
2022-01-04 17:03:11 -04:00
parent 5a4c6d0756
commit f1479a72d9
3 changed files with 52 additions and 82 deletions

View File

@@ -36,12 +36,6 @@ TEST_CASE("rest_endpoint", "[server_basic]")
REQUIRE(response.code == HTTPCode::Ok);
}
SECTION("Querying a non-existent task should yield a 404")
{
auto response = HTTP_REQUEST(baseURL + "/v1/task/100/sample_name");
REQUIRE(response.code == HTTPCode::Not_Found);
}
SECTION("Task Missing Cores should Fail")
{
std::string taskSpec =
@@ -75,22 +69,24 @@ TEST_CASE("rest_endpoint", "[server_basic]")
}
while (true) {
auto [code, doc] = JSON_HTTP_REQUEST(baseURL + "/v1/task/0/sample_task");
REQUIRE(doc.IsObject());
REQUIRE(doc.HasMember("state"));
std::this_thread::sleep_for(250ms);
auto [code, doc] = JSON_HTTP_REQUEST(baseURL + "/v1/poll");
REQUIRE(doc.IsArray());
if (doc.Size() == 0)
continue;
std::string state = doc["state"].GetString();
if (state != "COMPLETED") {
std::this_thread::sleep_for(250ms);
}
else {
REQUIRE(doc.HasMember("attempt"));
auto attempt = attemptRecordFromJSON(doc["attempt"]);
const auto &task = doc[0];
REQUIRE(task.HasMember("state"));
std::string state = task["state"].GetString();
if (state != "COMPLETED")
continue;
REQUIRE(attempt.rc == 0);
REQUIRE(attempt.outputLog == "hello world\n");
break;
}
REQUIRE(task.HasMember("attempt"));
auto attempt = attemptRecordFromJSON(task["attempt"]);
REQUIRE(attempt.rc == 0);
REQUIRE(attempt.outputLog == "hello world\n");
break;
}
}
@@ -131,10 +127,11 @@ TEST_CASE("rest_endpoint", "[server_basic]")
// Ensure the current job is running
{
auto [code, doc] = JSON_HTTP_REQUEST(baseURL + "/v1/task/0/sample_task");
REQUIRE(doc.IsObject());
REQUIRE(doc.HasMember("state"));
REQUIRE(doc["state"] != "COMPLETED");
auto [code, doc] = JSON_HTTP_REQUEST(baseURL + "/v1/poll");
REQUIRE(doc.IsArray());
REQUIRE(doc.Size() > 0);
REQUIRE(doc[0].HasMember("state"));
REQUIRE(doc[0]["state"] != "COMPLETED");
}
// Stop it
@@ -146,25 +143,23 @@ TEST_CASE("rest_endpoint", "[server_basic]")
// Grab it and ensure it was killed
while (true) {
auto response = HTTP_REQUEST(baseURL + "/v1/task/0/sample_task");
auto [code, doc] = JSON_HTTP_REQUEST(baseURL + "/v1/poll");
REQUIRE(code == HTTPCode::Ok);
REQUIRE(response.code == HTTPCode::Ok);
rj::Document doc;
daggy::checkRJParse(doc.Parse(response.body.c_str()));
REQUIRE(doc.IsObject());
REQUIRE(doc.HasMember("state"));
REQUIRE(doc.IsArray());
if (doc.Size() == 0)
continue;
std::string state = doc["state"].GetString();
if (state != "COMPLETED") {
std::this_thread::sleep_for(250ms);
}
else {
REQUIRE(doc.HasMember("attempt"));
auto attempt = attemptRecordFromJSON(doc["attempt"]);
const auto &task = doc[0];
REQUIRE(task.HasMember("state"));
std::string state = task["state"].GetString();
if (state != "COMPLETED")
continue;
REQUIRE(attempt.rc != 0);
break;
}
REQUIRE(task.HasMember("attempt"));
auto attempt = attemptRecordFromJSON(task["attempt"]);
REQUIRE(attempt.rc != 0);
break;
}
}