Commit 8f91fe9e authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Check the behavior of ThreadPoolExecutor destruction

Summary: [Folly] Check the behavior of ThreadPoolExecutor destruction regarding execution or dropping of outstanding tasks.

Differential Revision: D9627237

fbshipit-source-id: 4bb3c1480cc94ceeb3e550f52c298e3d2dcf71c5
parent 146b07b5
......@@ -133,6 +133,47 @@ TEST(ThreadPoolExecutorTest, IOJoin) {
join<IOThreadPoolExecutor>();
}
template <class TPE>
static void destroy() {
TPE tpe(1);
std::atomic<int> completed(0);
auto f = [&]() {
burnMs(10)();
completed++;
};
for (int i = 0; i < 1000; i++) {
tpe.add(f);
}
tpe.stop();
EXPECT_GT(1000, completed);
}
// IOThreadPoolExecutor's destuctor joins all tasks. Outstanding tasks belong
// to the event base, will be executed upon its destruction, and cannot be
// taken back.
template <>
void destroy<IOThreadPoolExecutor>() {
Optional<IOThreadPoolExecutor> tpe(in_place, 1);
std::atomic<int> completed(0);
auto f = [&]() {
burnMs(10)();
completed++;
};
for (int i = 0; i < 10; i++) {
tpe->add(f);
}
tpe.clear();
EXPECT_EQ(10, completed);
}
TEST(ThreadPoolExecutorTest, CPUDestroy) {
destroy<CPUThreadPoolExecutor>();
}
TEST(ThreadPoolExecutorTest, IODestroy) {
destroy<IOThreadPoolExecutor>();
}
template <class TPE>
static void resizeUnderLoad() {
TPE tpe(10);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment