ClickHouse/dbms/Common/tests/gtest_thread_pool_loop.cpp

23 lines
418 B
C++
Raw Normal View History

#include <atomic>
#include <iostream>
2019-01-13 18:51:57 +00:00
#include <Common/ThreadPool.h>
2019-06-29 23:23:53 +00:00
#include <gtest/gtest.h>
2019-06-29 23:23:53 +00:00
TEST(ThreadPool, Loop)
{
2019-06-29 23:23:53 +00:00
std::atomic<int> res{0};
for (size_t i = 0; i < 1000; ++i)
{
size_t threads = 16;
ThreadPool pool(threads);
for (size_t j = 0; j < threads; ++j)
pool.scheduleOrThrowOnError([&] { ++res; });
pool.wait();
}
2019-06-29 23:23:53 +00:00
EXPECT_EQ(res, 16000);
}