- Removing Catch2 code from codebase, will pull it via FetchContent instead.
- Changing StdOutLogger to OStreamLogger, so that test cases output can be silenced.
This commit is contained in:
@@ -3,32 +3,39 @@
|
||||
|
||||
#include "daggy/ThreadPool.hpp"
|
||||
|
||||
#include "catch.hpp"
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
using namespace daggy;
|
||||
|
||||
TEST_CASE("Threadpool Construction", "[threadpool]") {
|
||||
std::atomic<uint32_t> cnt(0);
|
||||
ThreadPool tp(10);
|
||||
std::atomic<uint32_t> cnt(0);
|
||||
ThreadPool tp(10);
|
||||
|
||||
std::vector<std::future<uint32_t>> rets;
|
||||
std::vector<std::future<uint32_t>> rets;
|
||||
|
||||
SECTION("Adding large tasks queues with return values") {
|
||||
auto tq = std::make_shared<daggy::TaskQueue>();
|
||||
std::vector<std::future<uint32_t>> res;
|
||||
for (size_t i = 0; i < 100; ++i)
|
||||
res.emplace_back(std::move(tq->addTask([&cnt]() { cnt++; return cnt.load(); })));
|
||||
tp.addTasks(tq);
|
||||
for (auto & r : res) r.get();
|
||||
REQUIRE(cnt == 100);
|
||||
}
|
||||
SECTION("Adding large tasks queues with return values") {
|
||||
auto tq = std::make_shared<daggy::TaskQueue>();
|
||||
std::vector<std::future<uint32_t>> res;
|
||||
for (size_t i = 0; i < 100; ++i)
|
||||
res.emplace_back(std::move(tq->addTask([&cnt]() {
|
||||
cnt++;
|
||||
return cnt.load();
|
||||
})));
|
||||
tp.addTasks(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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user