Test UnboundedBlockingQueue in ThreadPoolExecutorTest
authorMaged Michael <magedmichael@fb.com>
Sun, 17 Dec 2017 01:20:04 +0000 (17:20 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Sun, 17 Dec 2017 01:35:31 +0000 (17:35 -0800)
Summary: Test UnboundedBlockingQueue for the case in D3527722

Reviewed By: ot

Differential Revision: D6587163

fbshipit-source-id: 1465991018187c5f841e6e3e7a11676390e2f8f2

folly/executors/test/ThreadPoolExecutorTest.cpp

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