Commit 8f2abf77 authored by Andrii Grynenko's avatar Andrii Grynenko Committed by Facebook Github Bot

Fix folly::coro unit tests to not use InlineExecutor

Reviewed By: yfeldblum, lewissbaker

Differential Revision: D18052431

fbshipit-source-id: 9fb1b3faba25093cf67bdf9c6cbe5cc70794deee
parent f54c24f8
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#if FOLLY_HAS_COROUTINES #if FOLLY_HAS_COROUTINES
#include <folly/executors/InlineExecutor.h> #include <folly/executors/ManualExecutor.h>
#include <folly/experimental/coro/Baton.h> #include <folly/experimental/coro/Baton.h>
#include <folly/experimental/coro/Task.h> #include <folly/experimental/coro/Task.h>
#include <folly/portability/GTest.h> #include <folly/portability/GTest.h>
...@@ -59,12 +59,15 @@ TEST(Baton, AwaitBaton) { ...@@ -59,12 +59,15 @@ TEST(Baton, AwaitBaton) {
CHECK(!reachedBeforeAwait); CHECK(!reachedBeforeAwait);
CHECK(!reachedAfterAwait); CHECK(!reachedAfterAwait);
auto f = std::move(t).scheduleOn(&InlineExecutor::instance()).start(); ManualExecutor executor;
auto f = std::move(t).scheduleOn(&executor).start();
executor.drain();
CHECK(reachedBeforeAwait); CHECK(reachedBeforeAwait);
CHECK(!reachedAfterAwait); CHECK(!reachedAfterAwait);
baton.post(); baton.post();
executor.drain();
CHECK(reachedAfterAwait); CHECK(reachedAfterAwait);
} }
...@@ -92,8 +95,10 @@ TEST(Baton, MultiAwaitBaton) { ...@@ -92,8 +95,10 @@ TEST(Baton, MultiAwaitBaton) {
coro::Task<void> t1 = makeTask1(); coro::Task<void> t1 = makeTask1();
coro::Task<void> t2 = makeTask2(); coro::Task<void> t2 = makeTask2();
auto f1 = std::move(t1).scheduleOn(&InlineExecutor::instance()).start(); ManualExecutor executor;
auto f2 = std::move(t2).scheduleOn(&InlineExecutor::instance()).start(); auto f1 = std::move(t1).scheduleOn(&executor).start();
auto f2 = std::move(t2).scheduleOn(&executor).start();
executor.drain();
CHECK(reachedBeforeAwait1); CHECK(reachedBeforeAwait1);
CHECK(reachedBeforeAwait2); CHECK(reachedBeforeAwait2);
...@@ -101,6 +106,7 @@ TEST(Baton, MultiAwaitBaton) { ...@@ -101,6 +106,7 @@ TEST(Baton, MultiAwaitBaton) {
CHECK(!reachedAfterAwait2); CHECK(!reachedAfterAwait2);
baton.post(); baton.post();
executor.drain();
CHECK(f1.isReady()); CHECK(f1.isReady());
CHECK(f2.isReady()); CHECK(f2.isReady());
......
...@@ -101,7 +101,7 @@ TEST(Coro, TaskOfMoveOnly) { ...@@ -101,7 +101,7 @@ TEST(Coro, TaskOfMoveOnly) {
co_return std::make_unique<int>(123); co_return std::make_unique<int>(123);
}; };
auto p = coro::blockingWait(f().scheduleOn(&InlineExecutor::instance())); auto p = coro::blockingWait(f());
EXPECT_TRUE(p); EXPECT_TRUE(p);
EXPECT_EQ(123, *p); EXPECT_EQ(123, *p);
} }
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#if FOLLY_HAS_COROUTINES #if FOLLY_HAS_COROUTINES
#include <folly/executors/CPUThreadPoolExecutor.h> #include <folly/executors/CPUThreadPoolExecutor.h>
#include <folly/executors/InlineExecutor.h>
#include <folly/executors/ManualExecutor.h> #include <folly/executors/ManualExecutor.h>
#include <folly/experimental/coro/Baton.h> #include <folly/experimental/coro/Baton.h>
#include <folly/experimental/coro/BlockingWait.h> #include <folly/experimental/coro/BlockingWait.h>
...@@ -71,13 +70,15 @@ TEST(Mutex, LockAsync) { ...@@ -71,13 +70,15 @@ TEST(Mutex, LockAsync) {
m.unlock(); m.unlock();
}; };
auto& inlineExecutor = InlineExecutor::instance(); ManualExecutor executor;
auto f1 = makeTask(b1).scheduleOn(&inlineExecutor).start(); auto f1 = makeTask(b1).scheduleOn(&executor).start();
executor.drain();
CHECK_EQ(1, value); CHECK_EQ(1, value);
CHECK(!m.try_lock()); CHECK(!m.try_lock());
auto f2 = makeTask(b2).scheduleOn(&inlineExecutor).start(); auto f2 = makeTask(b2).scheduleOn(&executor).start();
executor.drain();
CHECK_EQ(1, value); CHECK_EQ(1, value);
// This will resume f1 coroutine and let it release the // This will resume f1 coroutine and let it release the
...@@ -85,11 +86,13 @@ TEST(Mutex, LockAsync) { ...@@ -85,11 +86,13 @@ TEST(Mutex, LockAsync) {
// at co_await m.lockAsync() which will then increment the value // at co_await m.lockAsync() which will then increment the value
// before becoming blocked on // before becoming blocked on
b1.post(); b1.post();
executor.drain();
CHECK_EQ(3, value); CHECK_EQ(3, value);
CHECK(!m.try_lock()); CHECK(!m.try_lock());
b2.post(); b2.post();
executor.drain();
CHECK_EQ(4, value); CHECK_EQ(4, value);
CHECK(m.try_lock()); CHECK(m.try_lock());
} }
...@@ -108,13 +111,15 @@ TEST(Mutex, ScopedLockAsync) { ...@@ -108,13 +111,15 @@ TEST(Mutex, ScopedLockAsync) {
++value; ++value;
}; };
auto& inlineExecutor = InlineExecutor::instance(); ManualExecutor executor;
auto f1 = makeTask(b1).scheduleOn(&inlineExecutor).start(); auto f1 = makeTask(b1).scheduleOn(&executor).start();
executor.drain();
CHECK_EQ(1, value); CHECK_EQ(1, value);
CHECK(!m.try_lock()); CHECK(!m.try_lock());
auto f2 = makeTask(b2).scheduleOn(&inlineExecutor).start(); auto f2 = makeTask(b2).scheduleOn(&executor).start();
executor.drain();
CHECK_EQ(1, value); CHECK_EQ(1, value);
// This will resume f1 coroutine and let it release the // This will resume f1 coroutine and let it release the
...@@ -122,11 +127,13 @@ TEST(Mutex, ScopedLockAsync) { ...@@ -122,11 +127,13 @@ TEST(Mutex, ScopedLockAsync) {
// at co_await m.lockAsync() which will then increment the value // at co_await m.lockAsync() which will then increment the value
// before becoming blocked on b2. // before becoming blocked on b2.
b1.post(); b1.post();
executor.drain();
CHECK_EQ(3, value); CHECK_EQ(3, value);
CHECK(!m.try_lock()); CHECK(!m.try_lock());
b2.post(); b2.post();
executor.drain();
CHECK_EQ(4, value); CHECK_EQ(4, value);
CHECK(m.try_lock()); CHECK(m.try_lock());
} }
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#if FOLLY_HAS_COROUTINES #if FOLLY_HAS_COROUTINES
#include <folly/executors/CPUThreadPoolExecutor.h> #include <folly/executors/CPUThreadPoolExecutor.h>
#include <folly/executors/InlineExecutor.h>
#include <folly/executors/ManualExecutor.h> #include <folly/executors/ManualExecutor.h>
#include <folly/experimental/coro/Baton.h> #include <folly/experimental/coro/Baton.h>
#include <folly/experimental/coro/BlockingWait.h> #include <folly/experimental/coro/BlockingWait.h>
...@@ -72,7 +71,7 @@ TEST(SharedMutex, ManualLockAsync) { ...@@ -72,7 +71,7 @@ TEST(SharedMutex, ManualLockAsync) {
mutex.unlock(); mutex.unlock();
}; };
auto& executor = InlineExecutor::instance(); ManualExecutor executor;
{ {
coro::Baton b1; coro::Baton b1;
...@@ -86,22 +85,28 @@ TEST(SharedMutex, ManualLockAsync) { ...@@ -86,22 +85,28 @@ TEST(SharedMutex, ManualLockAsync) {
auto w1 = makeWriterTask(b3).scheduleOn(&executor).start(); auto w1 = makeWriterTask(b3).scheduleOn(&executor).start();
auto w2 = makeWriterTask(b4).scheduleOn(&executor).start(); auto w2 = makeWriterTask(b4).scheduleOn(&executor).start();
auto r3 = makeReaderTask(b5).scheduleOn(&executor).start(); auto r3 = makeReaderTask(b5).scheduleOn(&executor).start();
executor.drain();
b1.post(); b1.post();
executor.drain();
CHECK_EQ(0, std::move(r1).get()); CHECK_EQ(0, std::move(r1).get());
b2.post(); b2.post();
executor.drain();
CHECK_EQ(0, std::move(r2).get()); CHECK_EQ(0, std::move(r2).get());
b3.post(); b3.post();
executor.drain();
CHECK_EQ(1, value); CHECK_EQ(1, value);
b4.post(); b4.post();
executor.drain();
CHECK_EQ(2, value); CHECK_EQ(2, value);
// This reader should have had to wait for the prior two write locks // This reader should have had to wait for the prior two write locks
// to complete before it acquired the read-lock. // to complete before it acquired the read-lock.
b5.post(); b5.post();
executor.drain();
CHECK_EQ(2, std::move(r3).get()); CHECK_EQ(2, std::move(r3).get());
} }
} }
...@@ -122,7 +127,7 @@ TEST(SharedMutex, ScopedLockAsync) { ...@@ -122,7 +127,7 @@ TEST(SharedMutex, ScopedLockAsync) {
value += 1; value += 1;
}; };
auto& executor = InlineExecutor::instance(); ManualExecutor executor;
{ {
coro::Baton b1; coro::Baton b1;
...@@ -138,20 +143,25 @@ TEST(SharedMutex, ScopedLockAsync) { ...@@ -138,20 +143,25 @@ TEST(SharedMutex, ScopedLockAsync) {
auto r3 = makeReaderTask(b5).scheduleOn(&executor).start(); auto r3 = makeReaderTask(b5).scheduleOn(&executor).start();
b1.post(); b1.post();
executor.drain();
CHECK_EQ(0, std::move(r1).get()); CHECK_EQ(0, std::move(r1).get());
b2.post(); b2.post();
executor.drain();
CHECK_EQ(0, std::move(r2).get()); CHECK_EQ(0, std::move(r2).get());
b3.post(); b3.post();
executor.drain();
CHECK_EQ(1, value); CHECK_EQ(1, value);
b4.post(); b4.post();
executor.drain();
CHECK_EQ(2, value); CHECK_EQ(2, value);
// This reader should have had to wait for the prior two write locks // This reader should have had to wait for the prior two write locks
// to complete before it acquired the read-lock. // to complete before it acquired the read-lock.
b5.post(); b5.post();
executor.drain();
CHECK_EQ(2, std::move(r3).get()); CHECK_EQ(2, std::move(r3).get());
} }
} }
......
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