- Changing how DAG is represented, both in code and how DAGs are defined in JSON. - Removing std::vector<Task> representation in favour of a map that will enforce unique task names - Task names now have a name (generated), and a definedName. - Adding support to loggers to add tasks after a DAGRun has been initialized.
68 lines
1.9 KiB
C++
68 lines
1.9 KiB
C++
#include <iostream>
|
|
#include <filesystem>
|
|
#include <fstream>
|
|
|
|
#include <catch2/catch.hpp>
|
|
|
|
#include "daggy/loggers/dag_run/FileSystemLogger.hpp"
|
|
#include "daggy/loggers/dag_run/OStreamLogger.hpp"
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
using namespace daggy;
|
|
using namespace daggy::loggers::dag_run;
|
|
|
|
const TaskList SAMPLE_TASKS{
|
|
{"work_a", Task{.command{"/bin/echo", "a"}, .children{"c"}}},
|
|
{"work_b", Task{.command{"/bin/echo", "b"}, .children{"c"}}},
|
|
{"work_c", Task{.command{"/bin/echo", "c"}}}
|
|
};
|
|
|
|
inline DAGRunID testDAGRunInit(DAGRunLogger &logger, const std::string &name, const TaskList &tasks) {
|
|
auto runID = logger.startDAGRun(name, tasks);
|
|
auto dagRun = logger.getDAGRun(runID);
|
|
|
|
REQUIRE(dagRun.tasks == tasks);
|
|
|
|
REQUIRE(dagRun.taskRunStates.size() == tasks.size());
|
|
auto nonQueuedTask = std::find_if(dagRun.taskRunStates.begin(), dagRun.taskRunStates.end(),
|
|
[](const auto &a) { return a.second != +RunState::QUEUED; });
|
|
REQUIRE(nonQueuedTask == dagRun.taskRunStates.end());
|
|
|
|
REQUIRE(dagRun.dagStateChanges.size() == 1);
|
|
REQUIRE(dagRun.dagStateChanges.back().newState == +RunState::QUEUED);
|
|
return runID;
|
|
}
|
|
|
|
/*
|
|
TEST_CASE("Filesystem Logger", "[filesystem_logger]") {
|
|
const fs::path logRoot{"fs_logger_unit"};
|
|
auto cleanup = [&]() {
|
|
if (fs::exists(logRoot)) {
|
|
fs::remove_all(logRoot);
|
|
}
|
|
};
|
|
|
|
//cleanup();
|
|
daggy::loggers::dag_run::FileSystemLogger logger(logRoot);
|
|
|
|
SECTION("DAGRun Starts") {
|
|
testDAGRunInit(logger, "init_test", SAMPLE_TASKS);
|
|
}
|
|
|
|
// cleanup();
|
|
}
|
|
*/
|
|
|
|
TEST_CASE("ostream Logger", "[ostream_logger]") {
|
|
//cleanup();
|
|
std::stringstream ss;
|
|
daggy::loggers::dag_run::OStreamLogger logger(ss);
|
|
|
|
SECTION("DAGRun Starts") {
|
|
testDAGRunInit(logger, "init_test", SAMPLE_TASKS);
|
|
}
|
|
|
|
// cleanup();
|
|
}
|