Squashed commit of the following:

commit 8a4e0fb24d191bf1c1009bd4c8800b4adab21f81
Author: Ian Roddis <gitlab@ie2r.com>
Date:   Tue Oct 5 17:23:21 2021 -0300

    Adding support for commandString

commit 9055cbde34d2489065b03c25c02a8bea56e42d54
Author: Ian Roddis <gitlab@ie2r.com>
Date:   Tue Oct 5 17:10:01 2021 -0300

    Completing support for environment variables

commit 989adef378724bbc9451c5048ea9d1285eebe2f9
Author: Ian Roddis <gitlab@ie2r.com>
Date:   Tue Oct 5 12:29:31 2021 -0300

    Adding environment support to ForkingTaskExecutor
This commit is contained in:
Ian Roddis
2021-10-05 17:26:30 -03:00
parent 65ab439848
commit cfefdae4f3
5 changed files with 240 additions and 33 deletions

View File

@@ -1,5 +1,6 @@
#include <catch2/catch.hpp>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <thread>
@@ -7,6 +8,8 @@
#include "daggy/Utilities.hpp"
#include "daggy/executors/task/ForkingTaskExecutor.hpp"
namespace fs = std::filesystem;
TEST_CASE("forking_executor", "[forking_executor]")
{
daggy::executors::task::ForkingTaskExecutor ex(10);
@@ -27,6 +30,59 @@ TEST_CASE("forking_executor", "[forking_executor]")
REQUIRE(rec.errorLog.empty());
}
SECTION("Simple Run using commandString")
{
daggy::Task task{.job{{"commandString", R"(/usr/bin/echo "abc 123")"}}};
REQUIRE(ex.validateTaskParameters(task.job));
auto recFuture = ex.execute(0, "command", task);
auto rec = recFuture.get();
REQUIRE(rec.rc == 0);
REQUIRE(rec.outputLog.size() >= 6);
REQUIRE(rec.errorLog.empty());
}
SECTION("Simple run with environment")
{
// Create the shell script
auto scriptFile = fs::current_path() / "fork_simple.sh";
if (fs::exists(scriptFile))
fs::remove_all(scriptFile);
std::ofstream ofh(scriptFile);
ofh << "#!/bin/bash\necho \"${DAGGY_TEST_VAR}\"\necho "
"\"${DAGGY_TEST_VAR2}\"\n";
ofh.close();
fs::permissions(scriptFile, fs::perms::owner_all,
fs::perm_options::replace);
std::string valOne = "funky_times";
std::string valTwo = "bleep_bloop";
daggy::Task task{.job{{"command",
daggy::executors::task::ForkingTaskExecutor::Command{
scriptFile.string()}},
{"environment", std::vector<std::string>{
"DAGGY_TEST_VAR=" + valOne,
"DAGGY_TEST_VAR2=" + valTwo}}}};
REQUIRE(ex.validateTaskParameters(task.job));
auto recFuture = ex.execute(0, "command", task);
auto rec = recFuture.get();
REQUIRE(rec.rc == 0);
REQUIRE(rec.outputLog.size() >= 6);
REQUIRE(rec.outputLog.find(valOne) != std::string::npos);
REQUIRE(rec.outputLog.find(valTwo) != std::string::npos);
REQUIRE(rec.errorLog.empty());
if (fs::exists(scriptFile))
fs::remove_all(scriptFile);
}
SECTION("Error Run")
{
daggy::Task task{