Things mostly work, just a strange hang when executing code with forking executor

This commit is contained in:
Ian Roddis
2021-07-05 15:37:29 -03:00
parent 468993edb5
commit 9b9409d504
7 changed files with 195 additions and 107 deletions

23
tests/unit_scheduler.cpp Normal file
View File

@@ -0,0 +1,23 @@
#include <iostream>
#include <filesystem>
#include "daggy/executors/ForkingExecutor.hpp"
#include "daggy/Scheduler.hpp"
#include "catch.hpp"
TEST_CASE("Basic Scheduler Execution", "[scheduler]") {
daggy::executor::ForkingExecutor ex;
daggy::Scheduler sched(ex);
std::vector<daggy::Task> tasks {
daggy::Task{ "task_a", { "/usr/bin/echo", "task_a"}, 3, 30, { "task_c"} }
, daggy::Task{ "task_b", { "/usr/bin/echo", "task_b"}, 3, 30, { "task_c" } }
, daggy::Task{ "task_c", { "/usr/bin/echo", "task_c"}, 3, 30, {} }
};
SECTION("Simple Run") {
sched.scheduleDAG("Simple", tasks, {});
sched.drain();
}
}

View File

@@ -11,21 +11,24 @@ TEST_CASE("Threadpool Construction", "[threadpool]") {
std::atomic<uint32_t> cnt(0);
ThreadPool tp(10);
std::vector<std::future<void>> res;
std::vector<std::future<uint32_t>> rets;
SECTION("Simple runs") {
auto tq = std::make_shared<daggy::TaskQueue>();
std::vector<std::future<uint32_t>> res;
for (size_t i = 0; i < 100; ++i)
res.push_back(tp.addTask([&cnt]() { cnt++; return; }));
res.emplace_back(std::move(tq->addTask([&cnt]() { cnt++; return cnt.load(); })));
tp.addTaskQueue(tq);
for (auto & r : res) r.get();
REQUIRE(cnt == 100);
}
SECTION("Slow runs") {
std::vector<std::future<void>> res;
using namespace std::chrono_literals;
for (size_t i = 0; i < 100; ++i)
res.push_back(tp.addTask([&cnt]() { std::this_thread::sleep_for(20ms); cnt++; return; }));
for (auto & r : res) r.get();
REQUIRE(cnt == 100);
}
}