Commit 9cb50022 authored by Maged Michael's avatar Maged Michael Committed by Facebook Github Bot

Test UnboundedBlockingQueue in ThreadPoolExecutorTest

Summary: Test UnboundedBlockingQueue for the case in D3527722

Reviewed By: ot

Differential Revision: D6587163

fbshipit-source-id: 1465991018187c5f841e6e3e7a11676390e2f8f2
parent f4d97dc6
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <folly/executors/IOThreadPoolExecutor.h> #include <folly/executors/IOThreadPoolExecutor.h>
#include <folly/executors/ThreadPoolExecutor.h> #include <folly/executors/ThreadPoolExecutor.h>
#include <folly/executors/task_queue/LifoSemMPMCQueue.h> #include <folly/executors/task_queue/LifoSemMPMCQueue.h>
#include <folly/executors/task_queue/UnboundedBlockingQueue.h>
#include <folly/executors/thread_factory/PriorityThreadFactory.h> #include <folly/executors/thread_factory/PriorityThreadFactory.h>
#include <folly/portability/GTest.h> #include <folly/portability/GTest.h>
...@@ -478,10 +479,11 @@ struct SlowMover { ...@@ -478,10 +479,11 @@ struct SlowMover {
bool slow; bool slow;
}; };
TEST(ThreadPoolExecutorTest, BugD3527722) { template <typename Q>
void bugD3527722_test() {
// Test that the queue does not get stuck if writes are completed in // Test that the queue does not get stuck if writes are completed in
// order opposite to how they are initiated. // order opposite to how they are initiated.
LifoSemMPMCQueue<SlowMover> q(1024); Q q(1024);
std::atomic<int> turn{}; std::atomic<int> turn{};
std::thread consumer1([&] { std::thread consumer1([&] {
...@@ -515,6 +517,19 @@ TEST(ThreadPoolExecutorTest, BugD3527722) { ...@@ -515,6 +517,19 @@ TEST(ThreadPoolExecutorTest, BugD3527722) {
consumer2.join(); consumer2.join();
} }
TEST(ThreadPoolExecutorTest, LifoSemMPMCQueueBugD3527722) {
bugD3527722_test<LifoSemMPMCQueue<SlowMover>>();
}
template <typename T>
struct UBQ : public UnboundedBlockingQueue<T> {
explicit UBQ(int) {}
};
TEST(ThreadPoolExecutorTest, UnboundedBlockingQueueBugD3527722) {
bugD3527722_test<UBQ<SlowMover>>();
}
template <typename TPE, typename ERR_T> template <typename TPE, typename ERR_T>
static void ShutdownTest() { static void ShutdownTest() {
// test that adding a .then() after we have // test that adding a .then() after we have
......
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