2019-06-29 23:23:53 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <Common/ThreadPool.h>
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
|
|
|
|
bool check()
|
|
|
|
{
|
|
|
|
ThreadPool pool(10);
|
|
|
|
|
2019-10-17 14:41:27 +00:00
|
|
|
pool.scheduleOrThrowOnError([] { throw std::runtime_error("Hello, world!"); });
|
2019-06-29 23:23:53 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < 100; ++i)
|
2019-10-17 14:41:27 +00:00
|
|
|
pool.scheduleOrThrowOnError([] {}); /// An exception will be rethrown from this method.
|
2019-06-29 23:23:53 +00:00
|
|
|
}
|
|
|
|
catch (const std::runtime_error &)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
pool.wait();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(ThreadPool, ExceptionFromSchedule)
|
|
|
|
{
|
|
|
|
EXPECT_TRUE(check());
|
|
|
|
}
|