Commit 802676ff authored by Abhinav Rai's avatar Abhinav Rai Committed by Facebook Github Bot

Fix tests for ExecutorLoopController timer.

Summary:
Using a ThreadPoolExecutor instead of calling getCPUExecutor() to get one.
getCPUExecutor() by default returns an inline executor, which doesn't ensure that sleep is triggered on the same executor as the fiber loop.

Reviewed By: andriigrynenko

Differential Revision: D18353758

fbshipit-source-id: 6810d11b12de3f62ac5286dba00d2b4a9d447eba
parent a76c883b
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include <folly/futures/Future.h> #include <folly/futures/Future.h>
#include <folly/Conv.h> #include <folly/Conv.h>
#include <folly/executors/GlobalExecutor.h> #include <folly/executors/CPUThreadPoolExecutor.h>
#include <folly/fibers/AddTasks.h> #include <folly/fibers/AddTasks.h>
#include <folly/fibers/AtomicBatchDispatcher.h> #include <folly/fibers/AtomicBatchDispatcher.h>
#include <folly/fibers/BatchDispatcher.h> #include <folly/fibers/BatchDispatcher.h>
...@@ -1477,8 +1477,8 @@ TEST(FiberManager, batonWaitTimeoutHandler) { ...@@ -1477,8 +1477,8 @@ TEST(FiberManager, batonWaitTimeoutHandler) {
TEST(FiberManager, batonWaitTimeoutHandlerExecutor) { TEST(FiberManager, batonWaitTimeoutHandlerExecutor) {
Baton baton2; Baton baton2;
FiberManager manager( folly::CPUThreadPoolExecutor executor(1);
std::make_unique<ExecutorLoopController>(folly::getCPUExecutor().get())); FiberManager manager(std::make_unique<ExecutorLoopController>(&executor));
auto task = [&](size_t timeout_ms) { auto task = [&](size_t timeout_ms) {
Baton baton; Baton baton;
auto start = std::chrono::steady_clock::now(); auto start = std::chrono::steady_clock::now();
...@@ -1489,7 +1489,7 @@ TEST(FiberManager, batonWaitTimeoutHandlerExecutor) { ...@@ -1489,7 +1489,7 @@ TEST(FiberManager, batonWaitTimeoutHandlerExecutor) {
std::chrono::duration_cast<std::chrono::milliseconds>(finish - start) std::chrono::duration_cast<std::chrono::milliseconds>(finish - start)
.count(); .count();
EXPECT_GT(duration_ms, timeout_ms); EXPECT_GT(duration_ms, timeout_ms - 10);
EXPECT_LT(duration_ms, timeout_ms + 100); EXPECT_LT(duration_ms, timeout_ms + 100);
baton2.post(); baton2.post();
}; };
......
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