- Missed closing of file descriptor made ForkingTaskExecutor silently die after running out of FDs - Tightened up scope for locks to prevent http timeout - Simplified threadpool
44 lines
917 B
C++
44 lines
917 B
C++
#include <catch2/catch.hpp>
|
|
#include <future>
|
|
#include <iostream>
|
|
|
|
#include "daggy/ThreadPool.hpp"
|
|
|
|
using namespace daggy;
|
|
|
|
TEST_CASE("threadpool", "[threadpool]")
|
|
{
|
|
std::atomic<uint32_t> cnt(0);
|
|
ThreadPool tp(10);
|
|
|
|
std::vector<std::future<uint32_t>> rets;
|
|
|
|
SECTION("Adding large tasks queues with return values")
|
|
{
|
|
std::vector<std::future<uint32_t>> res;
|
|
for (size_t i = 0; i < 100; ++i)
|
|
res.emplace_back(tp.addTask([&cnt]() {
|
|
cnt++;
|
|
return cnt.load();
|
|
}));
|
|
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);
|
|
}
|
|
}
|