#include #include #include #include #include #include #include #include #include #include #include #include namespace rj = rapidjson; using namespace daggy; TEST_CASE("rest_endpoint", "[server_basic]") { std::stringstream ss; Pistache::Address listenSpec("localhost", Pistache::Port(0)); const ssize_t maxCores = 10, maxMemoryMB = 1000; GeneralLogger logger(std::cout, LogLevel::NONE); daggyr::Server server(listenSpec, maxCores, maxMemoryMB, logger); server.init(10); server.start(); const std::string host = "localhost:"; const std::string baseURL = host + std::to_string(server.getPort()); SECTION("Ready Endpoint") { auto response = HTTP_REQUEST(baseURL + "/ready"); REQUIRE(response.code == HTTPCode::Ok); } SECTION("Task Missing Cores should Fail") { std::string taskSpec = R"({ "job": { "command": [ "/bin/touch", "dagrun_{{FILE}}" ]}, "memoryMB": 100 })"; auto response = HTTP_REQUEST(baseURL + "/v1/task/0/sample_task", taskSpec, "POST"); REQUIRE(response.code == HTTPCode::Not_Acceptable); } SECTION("Task Missing MemoryMB should Fail") { std::string taskSpec = R"({ "job": { "command": [ "/bin/touch", "dagrun_{{FILE}}" ]}, "cores": 100 })"; auto response = HTTP_REQUEST(baseURL + "/v1/task/0/sample_task", taskSpec, "POST"); REQUIRE(response.code == HTTPCode::Not_Acceptable); } SECTION("Task submission and get result") { std::string taskSpec = R"({ "job": { "command": [ "/bin/echo", "hello", "world" ], "cores": "1", "memoryMB": "100" } })"; // Submit { auto response = HTTP_REQUEST(baseURL + "/v1/task/0/sample_task", taskSpec, "POST"); REQUIRE(response.code == HTTPCode::Ok); } while (true) { std::this_thread::sleep_for(250ms); auto [code, attemptJSON] = JSON_HTTP_REQUEST(baseURL + "/v1/task/0/sample_task"); if (code == HTTPCode::Not_Found) continue; auto attempt = attemptRecordFromJSON(attemptJSON); REQUIRE(attempt.rc == 0); REQUIRE(attempt.outputLog == "hello world\n"); break; } } server.shutdown(); }