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