Skip to content

Commit

Permalink
test: add unit test for thread init function
Browse files Browse the repository at this point in the history
  • Loading branch information
DeveloperPaul123 committed Apr 26, 2024
1 parent 7745a6c commit 05d5ce3
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/source/thread_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <algorithm>
#include <iostream>
#include <numeric>
#include <print>
#include <random>
#include <string>
#include <thread>
Expand Down Expand Up @@ -445,3 +446,14 @@ TEST_CASE("Ensure wait_for_tasks() properly blocks current execution.") {

CHECK_EQ(counter.load(), total_tasks);
}

TEST_CASE("Initialization function is called") {
std::atomic_int counter = 0;
{
dp::thread_pool pool(4, [&counter](std::size_t id) {
std::print("Thread {} initialized\n", id);
counter.fetch_add(1);
});
}
CHECK_EQ(counter.load(), 4);
}

0 comments on commit 05d5ce3

Please sign in to comment.