(>10kb). Squashed commit of the following: commit b87fa418b4aca78928186a8fa992bef701e044a4 Author: Ian Roddis <tech@kinesin.ca> Date: Mon Feb 14 12:55:34 2022 -0400 removing memory leak commit 5e284ab92dbea991262a08c0cd50d6fc2f912e3b Author: Ian Roddis <tech@kinesin.ca> Date: Mon Feb 14 11:58:57 2022 -0400 Speeding up serialization, fixing payload sizing issue on daggyr commit e5e358820da4c2587741abdc3b6b103e5a4d4dd3 Author: Ian Roddis <tech@kinesin.ca> Date: Sun Feb 13 22:24:04 2022 -0400 changing newlines to std::endl for flush goodness commit 705ec86b75be947e64f4124ec8017cba2c8465e6 Author: Ian Roddis <tech@kinesin.ca> Date: Sun Feb 13 22:16:56 2022 -0400 adding more logging commit aa3db9c23e55da7a0523dc57e268b605ce8faac3 Author: Ian Roddis <tech@kinesin.ca> Date: Sun Feb 13 22:13:56 2022 -0400 Adding threadid commit 3b1a0f1333b2d43bc5ecad0746435504babbaa61 Author: Ian Roddis <tech@kinesin.ca> Date: Sun Feb 13 22:13:24 2022 -0400 Adding some debugging commit 804507e65251858fa597b7c27bcece8d8dfd589d Author: Ian Roddis <tech@kinesin.ca> Date: Sun Feb 13 21:52:53 2022 -0400 Removing curl global cleanup
147 lines
4.1 KiB
C++
147 lines
4.1 KiB
C++
#include <catch2/catch.hpp>
|
|
#include <filesystem>
|
|
#include <fstream>
|
|
#include <iostream>
|
|
|
|
#include "daggy/Serialization.hpp"
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
TEST_CASE("parameter_deserialization", "[deserialize_parameters]")
|
|
{
|
|
SECTION("Basic Parse")
|
|
{
|
|
std::string testParams{
|
|
R"({"DATE": ["2021-05-06", "2021-05-07" ], "SOURCE": "name"})"};
|
|
auto params = daggy::configFromJSON(testParams);
|
|
REQUIRE(params.size() == 2);
|
|
REQUIRE(std::holds_alternative<std::vector<std::string>>(params["DATE"]));
|
|
REQUIRE(std::holds_alternative<std::string>(params["SOURCE"]));
|
|
}
|
|
SECTION("Invalid JSON")
|
|
{
|
|
std::string testParams{
|
|
R"({"DATE": ["2021-05-06", "2021-05-07" ], "SOURCE": "name")"};
|
|
REQUIRE_THROWS(daggy::configFromJSON(testParams));
|
|
}
|
|
SECTION("Non-string Keys")
|
|
{
|
|
std::string testParams{
|
|
R"({"DATE": ["2021-05-06", "2021-05-07" ], 6: "name"})"};
|
|
REQUIRE_THROWS(daggy::configFromJSON(testParams));
|
|
}
|
|
SECTION("Non-array/Non-string values")
|
|
{
|
|
std::string testParams{
|
|
R"({"DATE": ["2021-05-06", "2021-05-07" ], "SOURCE": {"name": "kevin"}})"};
|
|
REQUIRE_THROWS(daggy::configFromJSON(testParams));
|
|
}
|
|
}
|
|
|
|
TEST_CASE("task_deserialization", "[deserialize_task]")
|
|
{
|
|
SECTION("Build with no expansion")
|
|
{
|
|
std::string testTasks = R"({
|
|
"A": {
|
|
"job": { "command": ["/bin/echo", "A"] },
|
|
"children": ["C"]
|
|
},
|
|
"B": {
|
|
"job": {"command": ["/bin/echo", "B"]},
|
|
"children": ["C"]
|
|
},
|
|
"C": {
|
|
"job": {"command": ["/bin/echo", "C"]}
|
|
}
|
|
})";
|
|
auto tasks = daggy::tasksFromJSON(testTasks);
|
|
REQUIRE(tasks.size() == 3);
|
|
}
|
|
|
|
SECTION("Build with job defaults")
|
|
{
|
|
std::string testTasks = R"({
|
|
"A": {
|
|
"job": { "command": ["/bin/echo", "A"] },
|
|
"children": ["B"]
|
|
},
|
|
"B": {
|
|
"job": {
|
|
"command": ["/bin/echo", "C"],
|
|
"memory": "1G"
|
|
}
|
|
}
|
|
})";
|
|
daggy::ConfigValues jobDefaults{{"runtime", "60"}, {"memory", "300M"}};
|
|
auto tasks = daggy::tasksFromJSON(testTasks, jobDefaults);
|
|
REQUIRE(tasks.size() == 2);
|
|
REQUIRE(std::get<std::string>(tasks["A"].job["runtime"]) == "60");
|
|
REQUIRE(std::get<std::string>(tasks["A"].job["memory"]) == "300M");
|
|
REQUIRE(std::get<std::string>(tasks["B"].job["runtime"]) == "60");
|
|
REQUIRE(std::get<std::string>(tasks["B"].job["memory"]) == "1G");
|
|
}
|
|
}
|
|
|
|
TEST_CASE("task_serialization", "[serialize_tasks]")
|
|
{
|
|
SECTION("Build with no expansion")
|
|
{
|
|
std::string testTasks =
|
|
R"({"A": {"job": {"command": ["/bin/echo", "A"]}, "children": ["C"]}, "B": {"job": {"command": ["/bin/echo", "B"]}, "children": ["C"]}, "C": {"job": {"command": ["/bin/echo", "C"]}}})";
|
|
auto tasks = daggy::tasksFromJSON(testTasks);
|
|
|
|
auto genJSON = daggy::tasksToJSON(tasks);
|
|
auto regenTasks = daggy::tasksFromJSON(genJSON);
|
|
|
|
REQUIRE(regenTasks.size() == tasks.size());
|
|
|
|
for (const auto &[name, task] : regenTasks) {
|
|
const auto &other = tasks[name];
|
|
REQUIRE(task == other);
|
|
}
|
|
}
|
|
}
|
|
|
|
TEST_CASE("attempt_serialization", "[serialize_attempt]")
|
|
{
|
|
SECTION("Serialize Simple Attempt")
|
|
{
|
|
using namespace daggy;
|
|
|
|
AttemptRecord attempt{
|
|
.startTime = Clock::now(),
|
|
.stopTime = Clock::now(),
|
|
.rc = 0,
|
|
.executorLog = "",
|
|
.outputLog = "",
|
|
.errorLog = "",
|
|
};
|
|
|
|
auto json = attemptRecordToJSON(attempt);
|
|
|
|
rj::Document doc;
|
|
REQUIRE_NOTHROW(checkRJParse(doc.Parse(json.c_str()), "Parsing AttemptRecord"));
|
|
}
|
|
|
|
SECTION("Serialize Attempt with complicated logs")
|
|
{
|
|
using namespace daggy;
|
|
|
|
AttemptRecord attempt{
|
|
.startTime = Clock::now(),
|
|
.stopTime = Clock::now(),
|
|
.rc = 0,
|
|
.executorLog = "",
|
|
.outputLog = "This is a testament to\nmore complicated, \"potentially quoted\"\nproblem\tspaces\n",
|
|
.errorLog = "",
|
|
};
|
|
|
|
auto json = attemptRecordToJSON(attempt);
|
|
|
|
rj::Document doc;
|
|
REQUIRE_NOTHROW(checkRJParse(doc.Parse(json.c_str()), "Parsing AttemptRecord"));
|
|
}
|
|
|
|
}
|