| 1 | #include <atomic> |
|---|---|
| 2 | #include <iostream> |
| 3 | #include <Common/ThreadPool.h> |
| 4 | |
| 5 | #include <gtest/gtest.h> |
| 6 | |
| 7 | /// Test for thread self-removal when number of free threads in pool is too large. |
| 8 | /// Just checks that nothing weird happens. |
| 9 | |
| 10 | template <typename Pool> |
| 11 | int test() |
| 12 | { |
| 13 | Pool pool(10, 2, 10); |
| 14 | |
| 15 | std::atomic<int> counter{0}; |
| 16 | for (size_t i = 0; i < 10; ++i) |
| 17 | pool.scheduleOrThrowOnError([&]{ ++counter; }); |
| 18 | pool.wait(); |
| 19 | |
| 20 | return counter; |
| 21 | } |
| 22 | |
| 23 | TEST(ThreadPool, ThreadRemoval) |
| 24 | { |
| 25 | EXPECT_EQ(test<FreeThreadPool>(), 10); |
| 26 | EXPECT_EQ(test<ThreadPool>(), 10); |
| 27 | } |
| 28 |