Fixing up threadpool
This commit is contained in:
@@ -29,13 +29,22 @@ TEST_CASE("Basic Execution", "[forking_executor]") {
|
||||
}
|
||||
|
||||
SECTION("Large Output") {
|
||||
const std::string BIG_FILE{"/usr/share/dict/linux.words"};
|
||||
std::vector<std::string> cmd{"/usr/bin/cat", BIG_FILE};
|
||||
const std::vector<std::string> BIG_FILES{
|
||||
"/usr/share/dict/linux.words"
|
||||
, "/usr/share/dict/cracklib-small"
|
||||
, "/etc/ssh/moduli"
|
||||
};
|
||||
|
||||
auto rec = ex.runCommand(cmd);
|
||||
for (const auto & bigFile : BIG_FILES) {
|
||||
if (! std::filesystem::exists(bigFile)) continue;
|
||||
|
||||
REQUIRE(rec.rc == 0);
|
||||
REQUIRE(rec.output.size() == std::filesystem::file_size(BIG_FILE));
|
||||
REQUIRE(rec.error.empty());
|
||||
std::vector<std::string> cmd{"/usr/bin/cat", bigFile};
|
||||
|
||||
auto rec = ex.runCommand(cmd);
|
||||
|
||||
REQUIRE(rec.rc == 0);
|
||||
REQUIRE(rec.output.size() == std::filesystem::file_size(bigFile));
|
||||
REQUIRE(rec.error.empty());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,13 +12,20 @@ TEST_CASE("Threadpool Construction", "[threadpool]") {
|
||||
ThreadPool tp(10);
|
||||
|
||||
std::vector<std::future<void>> res;
|
||||
for (size_t i = 0; i < 100; ++i) {
|
||||
res.push_back(tp.addTask([&cnt]() -> void { cnt++; return; }));
|
||||
|
||||
SECTION("Simple runs") {
|
||||
for (size_t i = 0; i < 100; ++i)
|
||||
res.push_back(tp.addTask([&cnt]() { cnt++; return; }));
|
||||
for (auto & r : res) r.get();
|
||||
REQUIRE(cnt == 100);
|
||||
}
|
||||
|
||||
for (auto & r : res) {
|
||||
r.get();
|
||||
SECTION("Slow runs") {
|
||||
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);
|
||||
}
|
||||
|
||||
REQUIRE(cnt == 100);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user