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

Prefer TEST_F in folly/experimental/coro/

Summary: [Folly] Prefer `TEST_F` and tests named `...Test` in `folly/experimental/coro/`.

Reviewed By: lewissbaker

Differential Revision: D18746584

fbshipit-source-id: 49156a1dca5ef115bf12add5ceb38cb7905fac3d
parent f044ae2a
...@@ -36,14 +36,16 @@ AsyncGenerator<int> generateInts(int begin, int end) { ...@@ -36,14 +36,16 @@ AsyncGenerator<int> generateInts(int begin, int end) {
} // namespace } // namespace
TEST(AccumulateTest, NoOperationProvided) { class AccumulateTest : public testing::Test {};
TEST_F(AccumulateTest, NoOperationProvided) {
auto result = blockingWait(accumulate(generateInts(0, 5), 0)); auto result = blockingWait(accumulate(generateInts(0, 5), 0));
auto expected = 0 + 1 + 2 + 3 + 4; auto expected = 0 + 1 + 2 + 3 + 4;
EXPECT_EQ(result, expected); EXPECT_EQ(result, expected);
} }
TEST(AccumulateTest, OperationProvided) { TEST_F(AccumulateTest, OperationProvided) {
auto result = auto result =
blockingWait(accumulate(generateInts(1, 5), 1, std::multiplies{})); blockingWait(accumulate(generateInts(1, 5), 1, std::multiplies{}));
auto expected = 1 * 2 * 3 * 4; auto expected = 1 * 2 * 3 * 4;
......
...@@ -37,7 +37,9 @@ ...@@ -37,7 +37,9 @@
#include <string> #include <string>
#include <tuple> #include <tuple>
TEST(AsyncGenerator, DefaultConstructedGeneratorIsEmpty) { class AsyncGeneratorTest : public testing::Test {};
TEST_F(AsyncGeneratorTest, DefaultConstructedGeneratorIsEmpty) {
folly::coro::blockingWait([]() -> folly::coro::Task<void> { folly::coro::blockingWait([]() -> folly::coro::Task<void> {
folly::coro::AsyncGenerator<int> g; folly::coro::AsyncGenerator<int> g;
auto result = co_await g.next(); auto result = co_await g.next();
...@@ -45,7 +47,7 @@ TEST(AsyncGenerator, DefaultConstructedGeneratorIsEmpty) { ...@@ -45,7 +47,7 @@ TEST(AsyncGenerator, DefaultConstructedGeneratorIsEmpty) {
}()); }());
} }
TEST(AsyncGenerator, GeneratorDestroyedBeforeCallingBegin) { TEST_F(AsyncGeneratorTest, GeneratorDestroyedBeforeCallingBegin) {
bool started = false; bool started = false;
auto makeGenerator = [&]() -> folly::coro::AsyncGenerator<int> { auto makeGenerator = [&]() -> folly::coro::AsyncGenerator<int> {
started = true; started = true;
...@@ -60,7 +62,7 @@ TEST(AsyncGenerator, GeneratorDestroyedBeforeCallingBegin) { ...@@ -60,7 +62,7 @@ TEST(AsyncGenerator, GeneratorDestroyedBeforeCallingBegin) {
CHECK(!started); CHECK(!started);
} }
TEST(AsyncGenerator, PartiallyConsumingSequenceDestroysObjectsInScope) { TEST_F(AsyncGeneratorTest, PartiallyConsumingSequenceDestroysObjectsInScope) {
bool started = false; bool started = false;
bool destroyed = false; bool destroyed = false;
auto makeGenerator = [&]() -> folly::coro::AsyncGenerator<int> { auto makeGenerator = [&]() -> folly::coro::AsyncGenerator<int> {
...@@ -88,7 +90,7 @@ TEST(AsyncGenerator, PartiallyConsumingSequenceDestroysObjectsInScope) { ...@@ -88,7 +90,7 @@ TEST(AsyncGenerator, PartiallyConsumingSequenceDestroysObjectsInScope) {
}()); }());
} }
TEST(AsyncGenerator, FullyConsumeSequence) { TEST_F(AsyncGeneratorTest, FullyConsumeSequence) {
auto makeGenerator = []() -> folly::coro::AsyncGenerator<int> { auto makeGenerator = []() -> folly::coro::AsyncGenerator<int> {
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {
co_yield i; co_yield i;
...@@ -118,7 +120,7 @@ namespace { ...@@ -118,7 +120,7 @@ namespace {
struct SomeError : std::exception {}; struct SomeError : std::exception {};
} // namespace } // namespace
TEST(AsyncGenerator, ThrowExceptionBeforeFirstYield) { TEST_F(AsyncGeneratorTest, ThrowExceptionBeforeFirstYield) {
auto makeGenerator = []() -> folly::coro::AsyncGenerator<int> { auto makeGenerator = []() -> folly::coro::AsyncGenerator<int> {
if (true) { if (true) {
throw SomeError{}; throw SomeError{};
...@@ -139,7 +141,7 @@ TEST(AsyncGenerator, ThrowExceptionBeforeFirstYield) { ...@@ -139,7 +141,7 @@ TEST(AsyncGenerator, ThrowExceptionBeforeFirstYield) {
}()); }());
} }
TEST(AsyncGenerator, ThrowExceptionAfterFirstYield) { TEST_F(AsyncGeneratorTest, ThrowExceptionAfterFirstYield) {
auto makeGenerator = []() -> folly::coro::AsyncGenerator<int> { auto makeGenerator = []() -> folly::coro::AsyncGenerator<int> {
co_yield 42; co_yield 42;
throw SomeError{}; throw SomeError{};
...@@ -161,7 +163,9 @@ TEST(AsyncGenerator, ThrowExceptionAfterFirstYield) { ...@@ -161,7 +163,9 @@ TEST(AsyncGenerator, ThrowExceptionAfterFirstYield) {
}()); }());
} }
TEST(AsyncGenerator, ConsumingManySynchronousElementsDoesNotOverflowStack) { TEST_F(
AsyncGeneratorTest,
ConsumingManySynchronousElementsDoesNotOverflowStack) {
auto makeGenerator = []() -> folly::coro::AsyncGenerator<std::uint64_t> { auto makeGenerator = []() -> folly::coro::AsyncGenerator<std::uint64_t> {
for (std::uint64_t i = 0; i < 1'000'000; ++i) { for (std::uint64_t i = 0; i < 1'000'000; ++i) {
co_yield i; co_yield i;
...@@ -178,7 +182,7 @@ TEST(AsyncGenerator, ConsumingManySynchronousElementsDoesNotOverflowStack) { ...@@ -178,7 +182,7 @@ TEST(AsyncGenerator, ConsumingManySynchronousElementsDoesNotOverflowStack) {
}()); }());
} }
TEST(AsyncGenerator, ProduceResultsAsynchronously) { TEST_F(AsyncGeneratorTest, ProduceResultsAsynchronously) {
folly::coro::blockingWait([&]() -> folly::coro::Task<void> { folly::coro::blockingWait([&]() -> folly::coro::Task<void> {
folly::Executor* executor = co_await folly::coro::co_current_executor; folly::Executor* executor = co_await folly::coro::co_current_executor;
auto makeGenerator = [&]() -> folly::coro::AsyncGenerator<int> { auto makeGenerator = [&]() -> folly::coro::AsyncGenerator<int> {
...@@ -213,7 +217,7 @@ struct ConvertibleToIntReference { ...@@ -213,7 +217,7 @@ struct ConvertibleToIntReference {
} }
}; };
TEST(AsyncGenerator, GeneratorOfLValueReference) { TEST_F(AsyncGeneratorTest, GeneratorOfLValueReference) {
auto makeGenerator = []() -> folly::coro::AsyncGenerator<int&> { auto makeGenerator = []() -> folly::coro::AsyncGenerator<int&> {
int value = 10; int value = 10;
co_yield value; co_yield value;
...@@ -244,7 +248,7 @@ struct ConvertibleToInt { ...@@ -244,7 +248,7 @@ struct ConvertibleToInt {
} }
}; };
TEST(AsyncGenerator, GeneratorOfConstLValueReference) { TEST_F(AsyncGeneratorTest, GeneratorOfConstLValueReference) {
auto makeGenerator = []() -> folly::coro::AsyncGenerator<const int&> { auto makeGenerator = []() -> folly::coro::AsyncGenerator<const int&> {
int value = 10; int value = 10;
co_yield value; co_yield value;
...@@ -269,7 +273,7 @@ TEST(AsyncGenerator, GeneratorOfConstLValueReference) { ...@@ -269,7 +273,7 @@ TEST(AsyncGenerator, GeneratorOfConstLValueReference) {
}()); }());
} }
TEST(AsyncGenerator, GeneratorOfRValueReference) { TEST_F(AsyncGeneratorTest, GeneratorOfRValueReference) {
auto makeGenerator = auto makeGenerator =
[]() -> folly::coro::AsyncGenerator<std::unique_ptr<int>&&> { []() -> folly::coro::AsyncGenerator<std::unique_ptr<int>&&> {
co_yield std::make_unique<int>(10); co_yield std::make_unique<int>(10);
...@@ -309,7 +313,7 @@ struct MoveOnly { ...@@ -309,7 +313,7 @@ struct MoveOnly {
int value_; int value_;
}; };
TEST(AsyncGenerator, GeneratorOfMoveOnlyType) { TEST_F(AsyncGeneratorTest, GeneratorOfMoveOnlyType) {
auto makeGenerator = []() -> folly::coro::AsyncGenerator<MoveOnly> { auto makeGenerator = []() -> folly::coro::AsyncGenerator<MoveOnly> {
MoveOnly rvalue(1); MoveOnly rvalue(1);
co_yield std::move(rvalue); co_yield std::move(rvalue);
...@@ -334,7 +338,7 @@ TEST(AsyncGenerator, GeneratorOfMoveOnlyType) { ...@@ -334,7 +338,7 @@ TEST(AsyncGenerator, GeneratorOfMoveOnlyType) {
}()); }());
} }
TEST(AsyncGenerator, GeneratorOfConstValue) { TEST_F(AsyncGeneratorTest, GeneratorOfConstValue) {
auto makeGenerator = []() -> folly::coro::AsyncGenerator<const int> { auto makeGenerator = []() -> folly::coro::AsyncGenerator<const int> {
// OK to yield prvalue // OK to yield prvalue
co_yield 42; co_yield 42;
...@@ -360,7 +364,7 @@ TEST(AsyncGenerator, GeneratorOfConstValue) { ...@@ -360,7 +364,7 @@ TEST(AsyncGenerator, GeneratorOfConstValue) {
}()); }());
} }
TEST(AsyncGenerator, ExplicitValueType) { TEST_F(AsyncGeneratorTest, ExplicitValueType) {
std::map<std::string, std::string> items; std::map<std::string, std::string> items;
items["foo"] = "hello"; items["foo"] = "hello";
items["bar"] = "goodbye"; items["bar"] = "goodbye";
...@@ -390,7 +394,7 @@ TEST(AsyncGenerator, ExplicitValueType) { ...@@ -390,7 +394,7 @@ TEST(AsyncGenerator, ExplicitValueType) {
CHECK_EQ("au revoir", items["bar"]); CHECK_EQ("au revoir", items["bar"]);
} }
TEST(AsyncGenerator, InvokeLambda) { TEST_F(AsyncGeneratorTest, InvokeLambda) {
folly::coro::blockingWait([]() -> folly::coro::Task<void> { folly::coro::blockingWait([]() -> folly::coro::Task<void> {
auto ptr = std::make_unique<int>(123); auto ptr = std::make_unique<int>(123);
auto gen = folly::coro::co_invoke( auto gen = folly::coro::co_invoke(
...@@ -416,7 +420,7 @@ folly::coro::AsyncGenerator<Ref, Value> neverStream() { ...@@ -416,7 +420,7 @@ folly::coro::AsyncGenerator<Ref, Value> neverStream() {
co_await baton; co_await baton;
} }
TEST(AsyncGenerator, CancellationTokenPropagatesFromConsumer) { TEST_F(AsyncGeneratorTest, CancellationTokenPropagatesFromConsumer) {
folly::coro::blockingWait([]() -> folly::coro::Task<void> { folly::coro::blockingWait([]() -> folly::coro::Task<void> {
folly::CancellationSource cancelSource; folly::CancellationSource cancelSource;
bool suspended = false; bool suspended = false;
......
...@@ -27,7 +27,9 @@ ...@@ -27,7 +27,9 @@
using namespace folly; using namespace folly;
TEST(Baton, Ready) { class BatonTest : public testing::Test {};
TEST_F(BatonTest, Ready) {
coro::Baton b; coro::Baton b;
CHECK(!b.ready()); CHECK(!b.ready());
b.post(); b.post();
...@@ -36,14 +38,14 @@ TEST(Baton, Ready) { ...@@ -36,14 +38,14 @@ TEST(Baton, Ready) {
CHECK(!b.ready()); CHECK(!b.ready());
} }
TEST(Baton, InitiallyReady) { TEST_F(BatonTest, InitiallyReady) {
coro::Baton b{true}; coro::Baton b{true};
CHECK(b.ready()); CHECK(b.ready());
b.reset(); b.reset();
CHECK(!b.ready()); CHECK(!b.ready());
} }
TEST(Baton, AwaitBaton) { TEST_F(BatonTest, AwaitBaton) {
coro::Baton baton; coro::Baton baton;
bool reachedBeforeAwait = false; bool reachedBeforeAwait = false;
bool reachedAfterAwait = false; bool reachedAfterAwait = false;
...@@ -72,7 +74,7 @@ TEST(Baton, AwaitBaton) { ...@@ -72,7 +74,7 @@ TEST(Baton, AwaitBaton) {
CHECK(reachedAfterAwait); CHECK(reachedAfterAwait);
} }
TEST(Baton, MultiAwaitBaton) { TEST_F(BatonTest, MultiAwaitBaton) {
coro::Baton baton; coro::Baton baton;
bool reachedBeforeAwait1 = false; bool reachedBeforeAwait1 = false;
......
...@@ -60,11 +60,13 @@ static_assert( ...@@ -60,11 +60,13 @@ static_assert(
"object stored inside the Awaiter which would have been destructed " "object stored inside the Awaiter which would have been destructed "
"by the time blockingWait returns."); "by the time blockingWait returns.");
TEST(BlockingWait, SynchronousCompletionVoidResult) { class BlockingWaitTest : public testing::Test {};
TEST_F(BlockingWaitTest, SynchronousCompletionVoidResult) {
folly::coro::blockingWait(folly::coro::AwaitableReady<void>{}); folly::coro::blockingWait(folly::coro::AwaitableReady<void>{});
} }
TEST(BlockingWait, SynchronousCompletionPRValueResult) { TEST_F(BlockingWaitTest, SynchronousCompletionPRValueResult) {
EXPECT_EQ( EXPECT_EQ(
123, folly::coro::blockingWait(folly::coro::AwaitableReady<int>{123})); 123, folly::coro::blockingWait(folly::coro::AwaitableReady<int>{123}));
EXPECT_EQ( EXPECT_EQ(
...@@ -73,7 +75,7 @@ TEST(BlockingWait, SynchronousCompletionPRValueResult) { ...@@ -73,7 +75,7 @@ TEST(BlockingWait, SynchronousCompletionPRValueResult) {
folly::coro::AwaitableReady<std::string>("hello"))); folly::coro::AwaitableReady<std::string>("hello")));
} }
TEST(BlockingWait, SynchronousCompletionLValueResult) { TEST_F(BlockingWaitTest, SynchronousCompletionLValueResult) {
int value = 123; int value = 123;
int& result = int& result =
folly::coro::blockingWait(folly::coro::AwaitableReady<int&>{value}); folly::coro::blockingWait(folly::coro::AwaitableReady<int&>{value});
...@@ -81,7 +83,7 @@ TEST(BlockingWait, SynchronousCompletionLValueResult) { ...@@ -81,7 +83,7 @@ TEST(BlockingWait, SynchronousCompletionLValueResult) {
EXPECT_EQ(123, result); EXPECT_EQ(123, result);
} }
TEST(BlockingWait, SynchronousCompletionRValueResult) { TEST_F(BlockingWaitTest, SynchronousCompletionRValueResult) {
auto p = std::make_unique<int>(123); auto p = std::make_unique<int>(123);
auto* ptr = p.get(); auto* ptr = p.get();
...@@ -117,7 +119,7 @@ struct TrickyAwaitable { ...@@ -117,7 +119,7 @@ struct TrickyAwaitable {
} }
}; };
TEST(BlockingWait, ReturnRvalueReferenceFromAwaiter) { TEST_F(BlockingWaitTest, ReturnRvalueReferenceFromAwaiter) {
// This awaitable stores the result in the temporary Awaiter object that // This awaitable stores the result in the temporary Awaiter object that
// is placed on the coroutine frame as part of the co_await expression. // is placed on the coroutine frame as part of the co_await expression.
// It then returns an rvalue-reference to the value inside this temporary // It then returns an rvalue-reference to the value inside this temporary
...@@ -128,7 +130,7 @@ TEST(BlockingWait, ReturnRvalueReferenceFromAwaiter) { ...@@ -128,7 +130,7 @@ TEST(BlockingWait, ReturnRvalueReferenceFromAwaiter) {
CHECK_EQ(42, *result); CHECK_EQ(42, *result);
} }
TEST(BlockingWait, AsynchronousCompletionOnAnotherThread) { TEST_F(BlockingWaitTest, AsynchronousCompletionOnAnotherThread) {
folly::coro::Baton baton; folly::coro::Baton baton;
std::thread t{[&] { baton.post(); }}; std::thread t{[&] { baton.post(); }};
SCOPE_EXIT { SCOPE_EXIT {
...@@ -183,7 +185,7 @@ class SimplePromise { ...@@ -183,7 +185,7 @@ class SimplePromise {
folly::Optional<T> value_; folly::Optional<T> value_;
}; };
TEST(BlockingWait, WaitOnSimpleAsyncPromise) { TEST_F(BlockingWaitTest, WaitOnSimpleAsyncPromise) {
SimplePromise<std::string> p; SimplePromise<std::string> p;
std::thread t{[&] { p.emplace("hello coroutines!"); }}; std::thread t{[&] { p.emplace("hello coroutines!"); }};
SCOPE_EXIT { SCOPE_EXIT {
...@@ -200,7 +202,7 @@ struct MoveCounting { ...@@ -200,7 +202,7 @@ struct MoveCounting {
MoveCounting& operator=(MoveCounting&& other) = delete; MoveCounting& operator=(MoveCounting&& other) = delete;
}; };
TEST(BlockingWait, WaitOnMoveOnlyAsyncPromise) { TEST_F(BlockingWaitTest, WaitOnMoveOnlyAsyncPromise) {
SimplePromise<MoveCounting> p; SimplePromise<MoveCounting> p;
std::thread t{[&] { p.emplace(); }}; std::thread t{[&] { p.emplace(); }};
SCOPE_EXIT { SCOPE_EXIT {
...@@ -216,7 +218,7 @@ TEST(BlockingWait, WaitOnMoveOnlyAsyncPromise) { ...@@ -216,7 +218,7 @@ TEST(BlockingWait, WaitOnMoveOnlyAsyncPromise) {
EXPECT_GE(2, result.count_); EXPECT_GE(2, result.count_);
} }
TEST(BlockingWait, moveCountingAwaitableReady) { TEST_F(BlockingWaitTest, moveCountingAwaitableReady) {
folly::coro::AwaitableReady<MoveCounting> awaitable{MoveCounting{}}; folly::coro::AwaitableReady<MoveCounting> awaitable{MoveCounting{}};
auto result = folly::coro::blockingWait(awaitable); auto result = folly::coro::blockingWait(awaitable);
...@@ -228,7 +230,7 @@ TEST(BlockingWait, moveCountingAwaitableReady) { ...@@ -228,7 +230,7 @@ TEST(BlockingWait, moveCountingAwaitableReady) {
EXPECT_GE(4, result.count_); EXPECT_GE(4, result.count_);
} }
TEST(BlockingWait, WaitInFiber) { TEST_F(BlockingWaitTest, WaitInFiber) {
SimplePromise<int> promise; SimplePromise<int> promise;
folly::EventBase evb; folly::EventBase evb;
auto& fm = folly::fibers::getFiberManager(evb); auto& fm = folly::fibers::getFiberManager(evb);
...@@ -246,7 +248,7 @@ TEST(BlockingWait, WaitInFiber) { ...@@ -246,7 +248,7 @@ TEST(BlockingWait, WaitInFiber) {
EXPECT_EQ(42, std::move(future).get()); EXPECT_EQ(42, std::move(future).get());
} }
TEST(BlockingWait, WaitTaskInFiber) { TEST_F(BlockingWaitTest, WaitTaskInFiber) {
SimplePromise<int> promise; SimplePromise<int> promise;
folly::EventBase evb; folly::EventBase evb;
auto& fm = folly::fibers::getFiberManager(evb); auto& fm = folly::fibers::getFiberManager(evb);
...@@ -266,12 +268,12 @@ TEST(BlockingWait, WaitTaskInFiber) { ...@@ -266,12 +268,12 @@ TEST(BlockingWait, WaitTaskInFiber) {
EXPECT_EQ(42, std::move(future).get()); EXPECT_EQ(42, std::move(future).get());
} }
TEST(BlockingWait, WaitOnSemiFuture) { TEST_F(BlockingWaitTest, WaitOnSemiFuture) {
int result = folly::coro::blockingWait(folly::makeSemiFuture(123)); int result = folly::coro::blockingWait(folly::makeSemiFuture(123));
CHECK_EQ(result, 123); CHECK_EQ(result, 123);
} }
TEST(BlockingWait, RequestContext) { TEST_F(BlockingWaitTest, RequestContext) {
folly::RequestContext::create(); folly::RequestContext::create();
std::shared_ptr<folly::RequestContext> ctx1, ctx2; std::shared_ptr<folly::RequestContext> ctx1, ctx2;
ctx1 = folly::RequestContext::saveContext(); ctx1 = folly::RequestContext::saveContext();
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include <folly/portability/GTest.h> #include <folly/portability/GTest.h>
using namespace ::testing;
using namespace folly::coro; using namespace folly::coro;
namespace { namespace {
...@@ -46,7 +45,9 @@ Task<std::vector<int>> toVector(AsyncGenerator<int> generator) { ...@@ -46,7 +45,9 @@ Task<std::vector<int>> toVector(AsyncGenerator<int> generator) {
} // namespace } // namespace
TEST(ConcatTest, ConcatSingle) { class ConcatTest : public testing::Test {};
TEST_F(ConcatTest, ConcatSingle) {
auto gen = concat(generateInts(0, 5)); auto gen = concat(generateInts(0, 5));
auto result = blockingWait(toVector(std::move(gen))); auto result = blockingWait(toVector(std::move(gen)));
std::vector<int> expected{0, 1, 2, 3, 4}; std::vector<int> expected{0, 1, 2, 3, 4};
...@@ -54,7 +55,7 @@ TEST(ConcatTest, ConcatSingle) { ...@@ -54,7 +55,7 @@ TEST(ConcatTest, ConcatSingle) {
EXPECT_EQ(result, expected); EXPECT_EQ(result, expected);
} }
TEST(ConcatTest, ConcatMultiple) { TEST_F(ConcatTest, ConcatMultiple) {
auto gen = auto gen =
concat(generateInts(0, 5), generateInts(7, 10), generateInts(12, 15)); concat(generateInts(0, 5), generateInts(7, 10), generateInts(12, 15));
auto result = blockingWait(toVector(std::move(gen))); auto result = blockingWait(toVector(std::move(gen)));
......
...@@ -54,7 +54,9 @@ SemiFuture<int> semifuture_task42() { ...@@ -54,7 +54,9 @@ SemiFuture<int> semifuture_task42() {
return task42().semi(); return task42().semi();
} }
TEST(Coro, Basic) { class CoroTest : public testing::Test {};
TEST_F(CoroTest, Basic) {
ManualExecutor executor; ManualExecutor executor;
auto future = task42().scheduleOn(&executor).start(); auto future = task42().scheduleOn(&executor).start();
...@@ -66,7 +68,7 @@ TEST(Coro, Basic) { ...@@ -66,7 +68,7 @@ TEST(Coro, Basic) {
EXPECT_EQ(42, std::move(future).get()); EXPECT_EQ(42, std::move(future).get());
} }
TEST(Coro, BasicSemiFuture) { TEST_F(CoroTest, BasicSemiFuture) {
ManualExecutor executor; ManualExecutor executor;
auto future = semifuture_task42().via(&executor); auto future = semifuture_task42().via(&executor);
...@@ -79,7 +81,7 @@ TEST(Coro, BasicSemiFuture) { ...@@ -79,7 +81,7 @@ TEST(Coro, BasicSemiFuture) {
EXPECT_EQ(42, std::move(future).get()); EXPECT_EQ(42, std::move(future).get());
} }
TEST(Coro, BasicFuture) { TEST_F(CoroTest, BasicFuture) {
ManualExecutor executor; ManualExecutor executor;
auto future = task42().scheduleOn(&executor).start(); auto future = task42().scheduleOn(&executor).start();
...@@ -94,7 +96,7 @@ coro::Task<void> taskVoid() { ...@@ -94,7 +96,7 @@ coro::Task<void> taskVoid() {
co_return; co_return;
} }
TEST(Coro, Basic2) { TEST_F(CoroTest, Basic2) {
ManualExecutor executor; ManualExecutor executor;
auto future = taskVoid().scheduleOn(&executor).start(); auto future = taskVoid().scheduleOn(&executor).start();
...@@ -105,7 +107,7 @@ TEST(Coro, Basic2) { ...@@ -105,7 +107,7 @@ TEST(Coro, Basic2) {
EXPECT_TRUE(future.isReady()); EXPECT_TRUE(future.isReady());
} }
TEST(Coro, TaskOfMoveOnly) { TEST_F(CoroTest, TaskOfMoveOnly) {
auto f = []() -> coro::Task<std::unique_ptr<int>> { auto f = []() -> coro::Task<std::unique_ptr<int>> {
co_return std::make_unique<int>(123); co_return std::make_unique<int>(123);
}; };
...@@ -120,7 +122,7 @@ coro::Task<void> taskSleep() { ...@@ -120,7 +122,7 @@ coro::Task<void> taskSleep() {
co_return; co_return;
} }
TEST(Coro, Sleep) { TEST_F(CoroTest, Sleep) {
ScopedEventBaseThread evbThread; ScopedEventBaseThread evbThread;
auto startTime = std::chrono::steady_clock::now(); auto startTime = std::chrono::steady_clock::now();
...@@ -136,7 +138,7 @@ TEST(Coro, Sleep) { ...@@ -136,7 +138,7 @@ TEST(Coro, Sleep) {
chrono::round<std::chrono::seconds>(totalTime), std::chrono::seconds{1}); chrono::round<std::chrono::seconds>(totalTime), std::chrono::seconds{1});
} }
TEST(Coro, ExecutorKeepAlive) { TEST_F(CoroTest, ExecutorKeepAlive) {
auto future = [] { auto future = [] {
ScopedEventBaseThread evbThread; ScopedEventBaseThread evbThread;
...@@ -173,7 +175,7 @@ coro::Task<void> executorRec(int depth) { ...@@ -173,7 +175,7 @@ coro::Task<void> executorRec(int depth) {
co_await executorRec(depth - 1); co_await executorRec(depth - 1);
} }
TEST(Coro, ExecutorKeepAliveDummy) { TEST_F(CoroTest, ExecutorKeepAliveDummy) {
CountingExecutor executor; CountingExecutor executor;
executorRec(42).scheduleOn(&executor).start().via(&executor).getVia( executorRec(42).scheduleOn(&executor).start().via(&executor).getVia(
&executor); &executor);
...@@ -184,7 +186,7 @@ coro::Task<int> taskException() { ...@@ -184,7 +186,7 @@ coro::Task<int> taskException() {
co_return 42; co_return 42;
} }
TEST(Coro, FutureThrow) { TEST_F(CoroTest, FutureThrow) {
ManualExecutor executor; ManualExecutor executor;
auto future = taskException().scheduleOn(&executor).start(); auto future = taskException().scheduleOn(&executor).start();
...@@ -206,7 +208,7 @@ coro::Task<int> taskRecursion(int depth) { ...@@ -206,7 +208,7 @@ coro::Task<int> taskRecursion(int depth) {
co_return depth; co_return depth;
} }
TEST(Coro, LargeStack) { TEST_F(CoroTest, LargeStack) {
ScopedEventBaseThread evbThread; ScopedEventBaseThread evbThread;
auto task = taskRecursion(5000).scheduleOn(evbThread.getEventBase()); auto task = taskRecursion(5000).scheduleOn(evbThread.getEventBase());
...@@ -238,7 +240,7 @@ coro::Task<int> taskThread() { ...@@ -238,7 +240,7 @@ coro::Task<int> taskThread() {
co_return 42; co_return 42;
} }
TEST(Coro, NestedThreads) { TEST_F(CoroTest, NestedThreads) {
ScopedEventBaseThread evbThread; ScopedEventBaseThread evbThread;
auto task = taskThread().scheduleOn(evbThread.getEventBase()); auto task = taskThread().scheduleOn(evbThread.getEventBase());
EXPECT_EQ(42, coro::blockingWait(std::move(task))); EXPECT_EQ(42, coro::blockingWait(std::move(task)));
...@@ -250,7 +252,7 @@ coro::Task<int> taskGetCurrentExecutor(Executor* executor) { ...@@ -250,7 +252,7 @@ coro::Task<int> taskGetCurrentExecutor(Executor* executor) {
co_return co_await task42().scheduleOn(current); co_return co_await task42().scheduleOn(current);
} }
TEST(Coro, CurrentExecutor) { TEST_F(CoroTest, CurrentExecutor) {
ScopedEventBaseThread evbThread; ScopedEventBaseThread evbThread;
auto task = taskGetCurrentExecutor(evbThread.getEventBase()) auto task = taskGetCurrentExecutor(evbThread.getEventBase())
.scheduleOn(evbThread.getEventBase()); .scheduleOn(evbThread.getEventBase());
...@@ -301,7 +303,7 @@ coro::Task<void> taskTimedWaitFuture() { ...@@ -301,7 +303,7 @@ coro::Task<void> taskTimedWaitFuture() {
co_return; co_return;
} }
TEST(Coro, TimedWaitFuture) { TEST_F(CoroTest, TimedWaitFuture) {
coro::blockingWait(taskTimedWaitFuture()); coro::blockingWait(taskTimedWaitFuture());
} }
...@@ -339,11 +341,11 @@ coro::Task<void> taskTimedWaitTask() { ...@@ -339,11 +341,11 @@ coro::Task<void> taskTimedWaitTask() {
co_return; co_return;
} }
TEST(Coro, TimedWaitTask) { TEST_F(CoroTest, TimedWaitTask) {
coro::blockingWait(taskTimedWaitTask()); coro::blockingWait(taskTimedWaitTask());
} }
TEST(Coro, TimedWaitKeepAlive) { TEST_F(CoroTest, TimedWaitKeepAlive) {
auto start = std::chrono::steady_clock::now(); auto start = std::chrono::steady_clock::now();
coro::blockingWait([]() -> coro::Task<void> { coro::blockingWait([]() -> coro::Task<void> {
co_await coro::timed_wait( co_await coro::timed_wait(
...@@ -379,7 +381,7 @@ coro::Task<int> taskAwaitableWithOperator() { ...@@ -379,7 +381,7 @@ coro::Task<int> taskAwaitableWithOperator() {
co_return co_await AwaitableWithOperator(); co_return co_await AwaitableWithOperator();
} }
TEST(Coro, AwaitableWithOperator) { TEST_F(CoroTest, AwaitableWithOperator) {
EXPECT_EQ(42, coro::blockingWait(taskAwaitableWithOperator())); EXPECT_EQ(42, coro::blockingWait(taskAwaitableWithOperator()));
} }
...@@ -397,7 +399,7 @@ coro::Task<int> taskAwaitableWithMemberOperator() { ...@@ -397,7 +399,7 @@ coro::Task<int> taskAwaitableWithMemberOperator() {
co_return co_await AwaitableWithMemberOperator(); co_return co_await AwaitableWithMemberOperator();
} }
TEST(Coro, AwaitableWithMemberOperator) { TEST_F(CoroTest, AwaitableWithMemberOperator) {
EXPECT_EQ(42, coro::blockingWait(taskAwaitableWithMemberOperator())); EXPECT_EQ(42, coro::blockingWait(taskAwaitableWithMemberOperator()));
} }
...@@ -406,7 +408,7 @@ coro::Task<int> taskBaton(fibers::Baton& baton) { ...@@ -406,7 +408,7 @@ coro::Task<int> taskBaton(fibers::Baton& baton) {
co_return 42; co_return 42;
} }
TEST(Coro, Baton) { TEST_F(CoroTest, Baton) {
ManualExecutor executor; ManualExecutor executor;
fibers::Baton baton; fibers::Baton baton;
auto future = taskBaton(baton).scheduleOn(&executor).start(); auto future = taskBaton(baton).scheduleOn(&executor).start();
...@@ -429,15 +431,15 @@ coro::Task<Type> taskFuture(Type value) { ...@@ -429,15 +431,15 @@ coro::Task<Type> taskFuture(Type value) {
co_return co_await folly::makeFuture<Type>(std::move(value)); co_return co_await folly::makeFuture<Type>(std::move(value));
} }
TEST(Coro, FulfilledFuture) { TEST_F(CoroTest, FulfilledFuture) {
EXPECT_EQ(42, coro::blockingWait(taskFuture(42))); EXPECT_EQ(42, coro::blockingWait(taskFuture(42)));
} }
TEST(Coro, MoveOnlyReturn) { TEST_F(CoroTest, MoveOnlyReturn) {
EXPECT_EQ(42, *coro::blockingWait(taskFuture(std::make_unique<int>(42)))); EXPECT_EQ(42, *coro::blockingWait(taskFuture(std::make_unique<int>(42))));
} }
TEST(Coro, co_invoke) { TEST_F(CoroTest, co_invoke) {
ManualExecutor executor; ManualExecutor executor;
Promise<folly::Unit> p; Promise<folly::Unit> p;
auto coroFuture = auto coroFuture =
...@@ -456,7 +458,7 @@ TEST(Coro, co_invoke) { ...@@ -456,7 +458,7 @@ TEST(Coro, co_invoke) {
EXPECT_TRUE(coroFuture.isReady()); EXPECT_TRUE(coroFuture.isReady());
} }
TEST(Coro, Semaphore) { TEST_F(CoroTest, Semaphore) {
static constexpr size_t kTasks = 10; static constexpr size_t kTasks = 10;
static constexpr size_t kIterations = 10000; static constexpr size_t kIterations = 10000;
static constexpr size_t kNumTokens = 10; static constexpr size_t kNumTokens = 10;
...@@ -513,7 +515,7 @@ TEST(Coro, Semaphore) { ...@@ -513,7 +515,7 @@ TEST(Coro, Semaphore) {
} }
} }
TEST(Coro, FutureTry) { TEST_F(CoroTest, FutureTry) {
folly::coro::blockingWait([]() -> folly::coro::Task<void> { folly::coro::blockingWait([]() -> folly::coro::Task<void> {
{ {
auto result = co_await folly::coro::co_awaitTry(task42().semi()); auto result = co_await folly::coro::co_awaitTry(task42().semi());
...@@ -542,7 +544,7 @@ TEST(Coro, FutureTry) { ...@@ -542,7 +544,7 @@ TEST(Coro, FutureTry) {
}()); }());
} }
TEST(Coro, CancellableSleep) { TEST_F(CoroTest, CancellableSleep) {
using namespace std::chrono; using namespace std::chrono;
using namespace std::chrono_literals; using namespace std::chrono_literals;
...@@ -566,7 +568,7 @@ TEST(Coro, CancellableSleep) { ...@@ -566,7 +568,7 @@ TEST(Coro, CancellableSleep) {
CHECK((end - start) < 1s); CHECK((end - start) < 1s);
} }
TEST(Coro, DefaultConstructible) { TEST_F(CoroTest, DefaultConstructible) {
coro::blockingWait([]() -> coro::Task<void> { coro::blockingWait([]() -> coro::Task<void> {
auto s = co_await taskS(); auto s = co_await taskS();
EXPECT_EQ(42, s.x); EXPECT_EQ(42, s.x);
......
...@@ -26,7 +26,9 @@ ...@@ -26,7 +26,9 @@
#include <folly/portability/GTest.h> #include <folly/portability/GTest.h>
TEST(Task, CoRescheduleOnCurrentExecutor) { class CoRescheduleOnCurrentExecutorTest : public testing::Test {};
TEST_F(CoRescheduleOnCurrentExecutorTest, example) {
std::vector<int> results; std::vector<int> results;
folly::coro::blockingWait(folly::coro::collectAll( folly::coro::blockingWait(folly::coro::collectAll(
folly::coro::co_invoke([&]() -> folly::coro::Task<void> { folly::coro::co_invoke([&]() -> folly::coro::Task<void> {
......
...@@ -28,7 +28,9 @@ ...@@ -28,7 +28,9 @@
using namespace folly::coro; using namespace folly::coro;
TEST(Dematerialize, SimpleStream) { class DematerializeTest : public testing::Test {};
TEST_F(DematerializeTest, SimpleStream) {
struct MyError : std::exception {}; struct MyError : std::exception {};
const int seenEndOfStream = 100; const int seenEndOfStream = 100;
...@@ -95,7 +97,7 @@ TEST(Dematerialize, SimpleStream) { ...@@ -95,7 +97,7 @@ TEST(Dematerialize, SimpleStream) {
blockingWait(test(2)); blockingWait(test(2));
} }
TEST(Dematerialize, GeneratorOfRValueReference) { TEST_F(DematerializeTest, GeneratorOfRValueReference) {
auto makeGenerator = auto makeGenerator =
[]() -> folly::coro::AsyncGenerator<std::unique_ptr<int>&&> { []() -> folly::coro::AsyncGenerator<std::unique_ptr<int>&&> {
co_yield std::make_unique<int>(10); co_yield std::make_unique<int>(10);
...@@ -135,7 +137,7 @@ struct MoveOnly { ...@@ -135,7 +137,7 @@ struct MoveOnly {
int value_; int value_;
}; };
TEST(Dematerialize, GeneratorOfMoveOnlyType) { TEST_F(DematerializeTest, GeneratorOfMoveOnlyType) {
auto makeGenerator = []() -> folly::coro::AsyncGenerator<MoveOnly> { auto makeGenerator = []() -> folly::coro::AsyncGenerator<MoveOnly> {
MoveOnly rvalue(1); MoveOnly rvalue(1);
co_yield std::move(rvalue); co_yield std::move(rvalue);
......
...@@ -26,12 +26,14 @@ ...@@ -26,12 +26,14 @@
namespace folly { namespace folly {
namespace coro { namespace coro {
TEST(GeneratorTest, DefaultConstructed_EmptySequence) { class GeneratorTest : public testing::Test {};
TEST_F(GeneratorTest, DefaultConstructed_EmptySequence) {
Generator<std::uint32_t> ints; Generator<std::uint32_t> ints;
EXPECT_EQ(ints.begin(), ints.end()); EXPECT_EQ(ints.begin(), ints.end());
} }
TEST(GeneratorTest, NonRecursiveUse) { TEST_F(GeneratorTest, NonRecursiveUse) {
auto f = []() -> Generator<float> { auto f = []() -> Generator<float> {
co_yield 1.0f; co_yield 1.0f;
co_yield 2.0f; co_yield 2.0f;
...@@ -46,7 +48,7 @@ TEST(GeneratorTest, NonRecursiveUse) { ...@@ -46,7 +48,7 @@ TEST(GeneratorTest, NonRecursiveUse) {
EXPECT_EQ(iter, gen.end()); EXPECT_EQ(iter, gen.end());
} }
TEST(GeneratorTest, ThrowsBeforeYieldingFirstElement_RethrowsFromBegin) { TEST_F(GeneratorTest, ThrowsBeforeYieldingFirstElement_RethrowsFromBegin) {
class MyException : public std::exception {}; class MyException : public std::exception {};
auto f = []() -> Generator<std::uint32_t> { auto f = []() -> Generator<std::uint32_t> {
...@@ -58,7 +60,7 @@ TEST(GeneratorTest, ThrowsBeforeYieldingFirstElement_RethrowsFromBegin) { ...@@ -58,7 +60,7 @@ TEST(GeneratorTest, ThrowsBeforeYieldingFirstElement_RethrowsFromBegin) {
EXPECT_THROW(gen.begin(), MyException); EXPECT_THROW(gen.begin(), MyException);
} }
TEST(GeneratorTest, ThrowsAfterYieldingFirstElement_RethrowsFromIncrement) { TEST_F(GeneratorTest, ThrowsAfterYieldingFirstElement_RethrowsFromIncrement) {
class MyException : public std::exception {}; class MyException : public std::exception {};
auto f = []() -> Generator<std::uint32_t> { auto f = []() -> Generator<std::uint32_t> {
...@@ -72,7 +74,7 @@ TEST(GeneratorTest, ThrowsAfterYieldingFirstElement_RethrowsFromIncrement) { ...@@ -72,7 +74,7 @@ TEST(GeneratorTest, ThrowsAfterYieldingFirstElement_RethrowsFromIncrement) {
EXPECT_THROW(++iter, MyException); EXPECT_THROW(++iter, MyException);
} }
TEST(GeneratorTest, NotStartedUntilCalled) { TEST_F(GeneratorTest, NotStartedUntilCalled) {
bool reachedA = false; bool reachedA = false;
bool reachedB = false; bool reachedB = false;
bool reachedC = false; bool reachedC = false;
...@@ -99,7 +101,7 @@ TEST(GeneratorTest, NotStartedUntilCalled) { ...@@ -99,7 +101,7 @@ TEST(GeneratorTest, NotStartedUntilCalled) {
EXPECT_EQ(iter, gen.end()); EXPECT_EQ(iter, gen.end());
} }
TEST(GeneratorTest, DestroyedBeforeCompletion_DestructsObjectsOnStack) { TEST_F(GeneratorTest, DestroyedBeforeCompletion_DestructsObjectsOnStack) {
bool destructed = false; bool destructed = false;
bool completed = false; bool completed = false;
auto f = [&]() -> Generator<std::uint32_t> { auto f = [&]() -> Generator<std::uint32_t> {
...@@ -125,7 +127,7 @@ TEST(GeneratorTest, DestroyedBeforeCompletion_DestructsObjectsOnStack) { ...@@ -125,7 +127,7 @@ TEST(GeneratorTest, DestroyedBeforeCompletion_DestructsObjectsOnStack) {
EXPECT_TRUE(destructed); EXPECT_TRUE(destructed);
} }
TEST(GeneratorTest, SimpleRecursiveYield) { TEST_F(GeneratorTest, SimpleRecursiveYield) {
auto f = [](int n, auto& f) -> Generator<const std::uint32_t> { auto f = [](int n, auto& f) -> Generator<const std::uint32_t> {
co_yield n; co_yield n;
if (n > 0) { if (n > 0) {
...@@ -165,7 +167,7 @@ TEST(GeneratorTest, SimpleRecursiveYield) { ...@@ -165,7 +167,7 @@ TEST(GeneratorTest, SimpleRecursiveYield) {
} }
} }
TEST(GeneratorTest, NestedEmptyYield) { TEST_F(GeneratorTest, NestedEmptyYield) {
auto f = []() -> Generator<std::uint32_t> { co_return; }; auto f = []() -> Generator<std::uint32_t> { co_return; };
auto g = [&f]() -> Generator<std::uint32_t> { auto g = [&f]() -> Generator<std::uint32_t> {
...@@ -183,7 +185,7 @@ TEST(GeneratorTest, NestedEmptyYield) { ...@@ -183,7 +185,7 @@ TEST(GeneratorTest, NestedEmptyYield) {
EXPECT_EQ(iter, gen.end()); EXPECT_EQ(iter, gen.end());
} }
TEST(GeneratorTest, ExceptionThrownFromRecursiveCall_CanBeCaughtByCaller) { TEST_F(GeneratorTest, ExceptionThrownFromRecursiveCall_CanBeCaughtByCaller) {
class SomeException : public std::exception {}; class SomeException : public std::exception {};
auto f = [](std::uint32_t depth, auto&& f) -> Generator<std::uint32_t> { auto f = [](std::uint32_t depth, auto&& f) -> Generator<std::uint32_t> {
...@@ -210,7 +212,7 @@ TEST(GeneratorTest, ExceptionThrownFromRecursiveCall_CanBeCaughtByCaller) { ...@@ -210,7 +212,7 @@ TEST(GeneratorTest, ExceptionThrownFromRecursiveCall_CanBeCaughtByCaller) {
EXPECT_EQ(iter, gen.end()); EXPECT_EQ(iter, gen.end());
} }
TEST(GeneratorTest, ExceptionThrownFromNestedCall_CanBeCaughtByCaller) { TEST_F(GeneratorTest, ExceptionThrownFromNestedCall_CanBeCaughtByCaller) {
class SomeException : public std::exception {}; class SomeException : public std::exception {};
auto f = [](std::uint32_t depth, auto&& f) -> Generator<std::uint32_t> { auto f = [](std::uint32_t depth, auto&& f) -> Generator<std::uint32_t> {
...@@ -277,7 +279,7 @@ Generator<std::uint32_t> iterate_range(std::uint32_t begin, std::uint32_t end) { ...@@ -277,7 +279,7 @@ Generator<std::uint32_t> iterate_range(std::uint32_t begin, std::uint32_t end) {
} }
} // namespace } // namespace
TEST(GeneratorTest, UsageInStandardAlgorithms) { TEST_F(GeneratorTest, UsageInStandardAlgorithms) {
{ {
auto a = iterate_range(5, 30); auto a = iterate_range(5, 30);
auto b = iterate_range(5, 30); auto b = iterate_range(5, 30);
......
...@@ -27,7 +27,9 @@ ...@@ -27,7 +27,9 @@
template <typename T> template <typename T>
using InlineTask = folly::coro::detail::InlineTask<T>; using InlineTask = folly::coro::detail::InlineTask<T>;
TEST(InlineTask, CallVoidTaskWithoutAwaitingNeverRuns) { class InlineTaskTest : public testing::Test {};
TEST_F(InlineTaskTest, CallVoidTaskWithoutAwaitingNeverRuns) {
bool hasStarted = false; bool hasStarted = false;
auto f = [&]() -> InlineTask<void> { auto f = [&]() -> InlineTask<void> {
hasStarted = true; hasStarted = true;
...@@ -40,7 +42,7 @@ TEST(InlineTask, CallVoidTaskWithoutAwaitingNeverRuns) { ...@@ -40,7 +42,7 @@ TEST(InlineTask, CallVoidTaskWithoutAwaitingNeverRuns) {
EXPECT_FALSE(hasStarted); EXPECT_FALSE(hasStarted);
} }
TEST(InlineTask, CallValueTaskWithoutAwaitingNeverRuns) { TEST_F(InlineTaskTest, CallValueTaskWithoutAwaitingNeverRuns) {
bool hasStarted = false; bool hasStarted = false;
auto f = [&]() -> InlineTask<int> { auto f = [&]() -> InlineTask<int> {
hasStarted = true; hasStarted = true;
...@@ -53,7 +55,7 @@ TEST(InlineTask, CallValueTaskWithoutAwaitingNeverRuns) { ...@@ -53,7 +55,7 @@ TEST(InlineTask, CallValueTaskWithoutAwaitingNeverRuns) {
EXPECT_FALSE(hasStarted); EXPECT_FALSE(hasStarted);
} }
TEST(InlineTask, CallRefTaskWithoutAwaitingNeverRuns) { TEST_F(InlineTaskTest, CallRefTaskWithoutAwaitingNeverRuns) {
bool hasStarted = false; bool hasStarted = false;
int value; int value;
auto f = [&]() -> InlineTask<int&> { auto f = [&]() -> InlineTask<int&> {
...@@ -67,7 +69,7 @@ TEST(InlineTask, CallRefTaskWithoutAwaitingNeverRuns) { ...@@ -67,7 +69,7 @@ TEST(InlineTask, CallRefTaskWithoutAwaitingNeverRuns) {
EXPECT_FALSE(hasStarted); EXPECT_FALSE(hasStarted);
} }
TEST(InlineTask, SimpleVoidTask) { TEST_F(InlineTaskTest, SimpleVoidTask) {
bool hasRun = false; bool hasRun = false;
auto f = [&]() -> InlineTask<void> { auto f = [&]() -> InlineTask<void> {
hasRun = true; hasRun = true;
...@@ -79,7 +81,7 @@ TEST(InlineTask, SimpleVoidTask) { ...@@ -79,7 +81,7 @@ TEST(InlineTask, SimpleVoidTask) {
EXPECT_TRUE(hasRun); EXPECT_TRUE(hasRun);
} }
TEST(InlineTask, SimpleValueTask) { TEST_F(InlineTaskTest, SimpleValueTask) {
bool hasRun = false; bool hasRun = false;
auto f = [&]() -> InlineTask<int> { auto f = [&]() -> InlineTask<int> {
hasRun = true; hasRun = true;
...@@ -91,7 +93,7 @@ TEST(InlineTask, SimpleValueTask) { ...@@ -91,7 +93,7 @@ TEST(InlineTask, SimpleValueTask) {
EXPECT_TRUE(hasRun); EXPECT_TRUE(hasRun);
} }
TEST(InlineTask, SimpleRefTask) { TEST_F(InlineTaskTest, SimpleRefTask) {
bool hasRun = false; bool hasRun = false;
auto f = [&]() -> InlineTask<bool&> { auto f = [&]() -> InlineTask<bool&> {
hasRun = true; hasRun = true;
...@@ -128,7 +130,7 @@ struct TypeWithImplicitSingleValueConstructor { ...@@ -128,7 +130,7 @@ struct TypeWithImplicitSingleValueConstructor {
/* implicit */ TypeWithImplicitSingleValueConstructor(float x) : value_(x) {} /* implicit */ TypeWithImplicitSingleValueConstructor(float x) : value_(x) {}
}; };
TEST(InlineTask, ReturnValueWithInitializerListSyntax) { TEST_F(InlineTaskTest, ReturnValueWithInitializerListSyntax) {
auto f = []() -> InlineTask<TypeWithImplicitSingleValueConstructor> { auto f = []() -> InlineTask<TypeWithImplicitSingleValueConstructor> {
co_return{1.23f}; co_return{1.23f};
}; };
...@@ -146,7 +148,7 @@ struct TypeWithImplicitMultiValueConstructor { ...@@ -146,7 +148,7 @@ struct TypeWithImplicitMultiValueConstructor {
: s_(s), x_(x) {} : s_(s), x_(x) {}
}; };
TEST(InlineTask, ReturnValueWithInitializerListSyntax2) { TEST_F(InlineTaskTest, ReturnValueWithInitializerListSyntax2) {
auto f = []() -> InlineTask<TypeWithImplicitMultiValueConstructor> { auto f = []() -> InlineTask<TypeWithImplicitMultiValueConstructor> {
#if 0 #if 0
// Under clang: // Under clang:
...@@ -162,7 +164,7 @@ TEST(InlineTask, ReturnValueWithInitializerListSyntax2) { ...@@ -162,7 +164,7 @@ TEST(InlineTask, ReturnValueWithInitializerListSyntax2) {
EXPECT_EQ(3.1415f, result.x_); EXPECT_EQ(3.1415f, result.x_);
} }
TEST(InlineTask, TaskOfMoveOnlyType) { TEST_F(InlineTaskTest, TaskOfMoveOnlyType) {
auto f = []() -> InlineTask<MoveOnlyType> { co_return MoveOnlyType{42}; }; auto f = []() -> InlineTask<MoveOnlyType> { co_return MoveOnlyType{42}; };
auto x = folly::coro::blockingWait(f()); auto x = folly::coro::blockingWait(f());
...@@ -180,7 +182,7 @@ TEST(InlineTask, TaskOfMoveOnlyType) { ...@@ -180,7 +182,7 @@ TEST(InlineTask, TaskOfMoveOnlyType) {
EXPECT_TRUE(executed); EXPECT_TRUE(executed);
} }
TEST(InlineTask, MoveOnlyTypeNRVO) { TEST_F(InlineTaskTest, MoveOnlyTypeNRVO) {
auto f = []() -> InlineTask<MoveOnlyType> { auto f = []() -> InlineTask<MoveOnlyType> {
MoveOnlyType x{10}; MoveOnlyType x{10};
co_return x; co_return x;
...@@ -190,7 +192,7 @@ TEST(InlineTask, MoveOnlyTypeNRVO) { ...@@ -190,7 +192,7 @@ TEST(InlineTask, MoveOnlyTypeNRVO) {
EXPECT_EQ(10, x.value_); EXPECT_EQ(10, x.value_);
} }
TEST(InlineTask, ReturnLvalueReference) { TEST_F(InlineTaskTest, ReturnLvalueReference) {
int value = 0; int value = 0;
auto f = [&]() -> InlineTask<int&> { co_return value; }; auto f = [&]() -> InlineTask<int&> { co_return value; };
...@@ -200,7 +202,7 @@ TEST(InlineTask, ReturnLvalueReference) { ...@@ -200,7 +202,7 @@ TEST(InlineTask, ReturnLvalueReference) {
struct MyException : std::exception {}; struct MyException : std::exception {};
TEST(InlineTask, ExceptionsPropagateFromVoidTask) { TEST_F(InlineTaskTest, ExceptionsPropagateFromVoidTask) {
auto f = []() -> InlineTask<void> { auto f = []() -> InlineTask<void> {
co_await std::experimental::suspend_never{}; co_await std::experimental::suspend_never{};
throw MyException{}; throw MyException{};
...@@ -208,7 +210,7 @@ TEST(InlineTask, ExceptionsPropagateFromVoidTask) { ...@@ -208,7 +210,7 @@ TEST(InlineTask, ExceptionsPropagateFromVoidTask) {
EXPECT_THROW(folly::coro::blockingWait(f()), MyException); EXPECT_THROW(folly::coro::blockingWait(f()), MyException);
} }
TEST(InlineTask, ExceptionsPropagateFromValueTask) { TEST_F(InlineTaskTest, ExceptionsPropagateFromValueTask) {
auto f = []() -> InlineTask<int> { auto f = []() -> InlineTask<int> {
co_await std::experimental::suspend_never{}; co_await std::experimental::suspend_never{};
throw MyException{}; throw MyException{};
...@@ -216,7 +218,7 @@ TEST(InlineTask, ExceptionsPropagateFromValueTask) { ...@@ -216,7 +218,7 @@ TEST(InlineTask, ExceptionsPropagateFromValueTask) {
EXPECT_THROW(folly::coro::blockingWait(f()), MyException); EXPECT_THROW(folly::coro::blockingWait(f()), MyException);
} }
TEST(InlineTask, ExceptionsPropagateFromRefTask) { TEST_F(InlineTaskTest, ExceptionsPropagateFromRefTask) {
auto f = []() -> InlineTask<int&> { auto f = []() -> InlineTask<int&> {
co_await std::experimental::suspend_never{}; co_await std::experimental::suspend_never{};
throw MyException{}; throw MyException{};
...@@ -235,7 +237,7 @@ struct ThrowingCopyConstructor { ...@@ -235,7 +237,7 @@ struct ThrowingCopyConstructor {
ThrowingCopyConstructor& operator=(const ThrowingCopyConstructor&) = delete; ThrowingCopyConstructor& operator=(const ThrowingCopyConstructor&) = delete;
}; };
TEST(InlineTask, ExceptionsPropagateFromReturnValueConstructor) { TEST_F(InlineTaskTest, ExceptionsPropagateFromReturnValueConstructor) {
auto f = []() -> InlineTask<ThrowingCopyConstructor> { co_return{}; }; auto f = []() -> InlineTask<ThrowingCopyConstructor> { co_return{}; };
EXPECT_THROW(folly::coro::blockingWait(f()), MyException); EXPECT_THROW(folly::coro::blockingWait(f()), MyException);
} }
...@@ -246,7 +248,7 @@ InlineTask<void> recursiveTask(int depth) { ...@@ -246,7 +248,7 @@ InlineTask<void> recursiveTask(int depth) {
} }
} }
TEST(InlineTask, DeepRecursionDoesntStackOverflow) { TEST_F(InlineTaskTest, DeepRecursionDoesntStackOverflow) {
folly::coro::blockingWait(recursiveTask(500000)); folly::coro::blockingWait(recursiveTask(500000));
} }
...@@ -257,7 +259,7 @@ InlineTask<int> recursiveValueTask(int depth) { ...@@ -257,7 +259,7 @@ InlineTask<int> recursiveValueTask(int depth) {
co_return 0; co_return 0;
} }
TEST(InlineTask, DeepRecursionOfValueTaskDoesntStackOverflow) { TEST_F(InlineTaskTest, DeepRecursionOfValueTaskDoesntStackOverflow) {
EXPECT_EQ(500000, folly::coro::blockingWait(recursiveValueTask(500000))); EXPECT_EQ(500000, folly::coro::blockingWait(recursiveValueTask(500000)));
} }
...@@ -269,7 +271,7 @@ InlineTask<void> recursiveThrowingTask(int depth) { ...@@ -269,7 +271,7 @@ InlineTask<void> recursiveThrowingTask(int depth) {
throw MyException{}; throw MyException{};
} }
TEST(InlineTask, DeepRecursionOfExceptions) { TEST_F(InlineTaskTest, DeepRecursionOfExceptions) {
EXPECT_THROW( EXPECT_THROW(
folly::coro::blockingWait(recursiveThrowingTask(50000)), MyException); folly::coro::blockingWait(recursiveThrowingTask(50000)), MyException);
} }
......
...@@ -28,7 +28,9 @@ ...@@ -28,7 +28,9 @@
using namespace folly::coro; using namespace folly::coro;
TEST(Materialize, SimpleStream) { class MaterializeTest : public testing::Test {};
TEST_F(MaterializeTest, SimpleStream) {
struct MyError : std::exception {}; struct MyError : std::exception {};
const int seenEndOfStream = 100; const int seenEndOfStream = 100;
......
...@@ -32,7 +32,9 @@ ...@@ -32,7 +32,9 @@
using namespace folly::coro; using namespace folly::coro;
TEST(Merge, SimpleMerge) { class MergeTest : public testing::Test {};
TEST_F(MergeTest, SimpleMerge) {
blockingWait([]() -> Task<void> { blockingWait([]() -> Task<void> {
auto generator = merge( auto generator = merge(
co_await co_current_executor, co_await co_current_executor,
...@@ -60,7 +62,7 @@ TEST(Merge, SimpleMerge) { ...@@ -60,7 +62,7 @@ TEST(Merge, SimpleMerge) {
}()); }());
} }
TEST(Merge, TruncateStream) { TEST_F(MergeTest, TruncateStream) {
blockingWait([]() -> Task<void> { blockingWait([]() -> Task<void> {
int started = 0; int started = 0;
int completed = 0; int completed = 0;
...@@ -101,7 +103,7 @@ TEST(Merge, TruncateStream) { ...@@ -101,7 +103,7 @@ TEST(Merge, TruncateStream) {
}()); }());
} }
TEST(Merge, SequencesOfRValueReferences) { TEST_F(MergeTest, SequencesOfRValueReferences) {
blockingWait([]() -> Task<void> { blockingWait([]() -> Task<void> {
auto makeStreamOfStreams = auto makeStreamOfStreams =
[]() -> AsyncGenerator<AsyncGenerator<std::vector<int>&&>> { []() -> AsyncGenerator<AsyncGenerator<std::vector<int>&&>> {
...@@ -126,7 +128,7 @@ TEST(Merge, SequencesOfRValueReferences) { ...@@ -126,7 +128,7 @@ TEST(Merge, SequencesOfRValueReferences) {
}()); }());
} }
TEST(Merge, SequencesOfLValueReferences) { TEST_F(MergeTest, SequencesOfLValueReferences) {
blockingWait([]() -> Task<void> { blockingWait([]() -> Task<void> {
auto makeStreamOfStreams = auto makeStreamOfStreams =
[]() -> AsyncGenerator<AsyncGenerator<std::vector<int>&>> { []() -> AsyncGenerator<AsyncGenerator<std::vector<int>&>> {
...@@ -175,7 +177,7 @@ folly::coro::AsyncGenerator<Ref, Value> neverStream() { ...@@ -175,7 +177,7 @@ folly::coro::AsyncGenerator<Ref, Value> neverStream() {
co_await baton; co_await baton;
} }
TEST(Merge, CancellationTokenPropagatesToOuterFromConsumer) { TEST_F(MergeTest, CancellationTokenPropagatesToOuterFromConsumer) {
folly::coro::blockingWait([]() -> folly::coro::Task<void> { folly::coro::blockingWait([]() -> folly::coro::Task<void> {
folly::CancellationSource cancelSource; folly::CancellationSource cancelSource;
bool suspended = false; bool suspended = false;
...@@ -204,7 +206,7 @@ TEST(Merge, CancellationTokenPropagatesToOuterFromConsumer) { ...@@ -204,7 +206,7 @@ TEST(Merge, CancellationTokenPropagatesToOuterFromConsumer) {
}()); }());
} }
TEST(Merge, CancellationTokenPropagatesToInnerFromConsumer) { TEST_F(MergeTest, CancellationTokenPropagatesToInnerFromConsumer) {
folly::coro::blockingWait([]() -> folly::coro::Task<void> { folly::coro::blockingWait([]() -> folly::coro::Task<void> {
folly::CancellationSource cancelSource; folly::CancellationSource cancelSource;
bool suspended = false; bool suspended = false;
......
...@@ -28,7 +28,9 @@ ...@@ -28,7 +28,9 @@
using namespace folly::coro; using namespace folly::coro;
TEST(Multiplex, SimpleStream) { class MultiplexTest : public testing::Test {};
TEST_F(MultiplexTest, SimpleStream) {
struct MyError : std::exception {}; struct MyError : std::exception {};
blockingWait([]() -> Task<void> { blockingWait([]() -> Task<void> {
......
...@@ -31,7 +31,9 @@ ...@@ -31,7 +31,9 @@
using namespace folly; using namespace folly;
TEST(Mutex, TryLock) { class MutexTest : public testing::Test {};
TEST_F(MutexTest, TryLock) {
coro::Mutex m; coro::Mutex m;
CHECK(m.try_lock()); CHECK(m.try_lock());
CHECK(!m.try_lock()); CHECK(!m.try_lock());
...@@ -39,7 +41,7 @@ TEST(Mutex, TryLock) { ...@@ -39,7 +41,7 @@ TEST(Mutex, TryLock) {
CHECK(m.try_lock()); CHECK(m.try_lock());
} }
TEST(Mutex, ScopedLock) { TEST_F(MutexTest, ScopedLock) {
coro::Mutex m; coro::Mutex m;
{ {
std::unique_lock<coro::Mutex> lock{m, std::try_to_lock}; std::unique_lock<coro::Mutex> lock{m, std::try_to_lock};
...@@ -55,7 +57,7 @@ TEST(Mutex, ScopedLock) { ...@@ -55,7 +57,7 @@ TEST(Mutex, ScopedLock) {
m.unlock(); m.unlock();
} }
TEST(Mutex, LockAsync) { TEST_F(MutexTest, LockAsync) {
coro::Mutex m; coro::Mutex m;
coro::Baton b1; coro::Baton b1;
coro::Baton b2; coro::Baton b2;
...@@ -97,7 +99,7 @@ TEST(Mutex, LockAsync) { ...@@ -97,7 +99,7 @@ TEST(Mutex, LockAsync) {
CHECK(m.try_lock()); CHECK(m.try_lock());
} }
TEST(Mutex, ScopedLockAsync) { TEST_F(MutexTest, ScopedLockAsync) {
coro::Mutex m; coro::Mutex m;
coro::Baton b1; coro::Baton b1;
coro::Baton b2; coro::Baton b2;
...@@ -138,7 +140,7 @@ TEST(Mutex, ScopedLockAsync) { ...@@ -138,7 +140,7 @@ TEST(Mutex, ScopedLockAsync) {
CHECK(m.try_lock()); CHECK(m.try_lock());
} }
TEST(Mutex, ThreadSafety) { TEST_F(MutexTest, ThreadSafety) {
CPUThreadPoolExecutor threadPool{ CPUThreadPoolExecutor threadPool{
2, std::make_shared<NamedThreadFactory>("CPUThreadPool")}; 2, std::make_shared<NamedThreadFactory>("CPUThreadPool")};
......
...@@ -30,7 +30,9 @@ ...@@ -30,7 +30,9 @@
using namespace folly; using namespace folly;
TEST(SharedMutex, TryLock) { class SharedMutexTest : public testing::Test {};
TEST_F(SharedMutexTest, TryLock) {
coro::SharedMutex m; coro::SharedMutex m;
CHECK(m.try_lock()); CHECK(m.try_lock());
...@@ -52,7 +54,7 @@ TEST(SharedMutex, TryLock) { ...@@ -52,7 +54,7 @@ TEST(SharedMutex, TryLock) {
m.unlock(); m.unlock();
} }
TEST(SharedMutex, ManualLockAsync) { TEST_F(SharedMutexTest, ManualLockAsync) {
coro::SharedMutex mutex; coro::SharedMutex mutex;
int value = 0; int value = 0;
...@@ -111,7 +113,7 @@ TEST(SharedMutex, ManualLockAsync) { ...@@ -111,7 +113,7 @@ TEST(SharedMutex, ManualLockAsync) {
} }
} }
TEST(SharedMutex, ScopedLockAsync) { TEST_F(SharedMutexTest, ScopedLockAsync) {
coro::SharedMutex mutex; coro::SharedMutex mutex;
int value = 0; int value = 0;
...@@ -166,7 +168,7 @@ TEST(SharedMutex, ScopedLockAsync) { ...@@ -166,7 +168,7 @@ TEST(SharedMutex, ScopedLockAsync) {
} }
} }
TEST(SharedMutex, ThreadSafety) { TEST_F(SharedMutexTest, ThreadSafety) {
// Spin up a thread-pool with 3 threads and 6 coroutines // Spin up a thread-pool with 3 threads and 6 coroutines
// (2 writers, 4 readers) that are constantly spinning in a loop reading // (2 writers, 4 readers) that are constantly spinning in a loop reading
// and modifying some shared state. // and modifying some shared state.
......
...@@ -188,7 +188,9 @@ static coro::Task<void> parentRequest(int id) { ...@@ -188,7 +188,9 @@ static coro::Task<void> parentRequest(int id) {
CHECK(RequestContext::get()->getContextData(testToken2) == nullptr); CHECK(RequestContext::get()->getContextData(testToken2) == nullptr);
} }
TEST(Task, RequestContextIsPreservedAcrossSuspendResume) { class TaskTest : public testing::Test {};
TEST_F(TaskTest, RequestContextIsPreservedAcrossSuspendResume) {
ManualExecutor executor; ManualExecutor executor;
RequestContextScopeGuard requestScope; RequestContextScopeGuard requestScope;
...@@ -238,7 +240,7 @@ TEST(Task, RequestContextIsPreservedAcrossSuspendResume) { ...@@ -238,7 +240,7 @@ TEST(Task, RequestContextIsPreservedAcrossSuspendResume) {
} }
} }
TEST(Task, ContextPreservedAcrossMutexLock) { TEST_F(TaskTest, ContextPreservedAcrossMutexLock) {
folly::coro::Mutex mutex; folly::coro::Mutex mutex;
auto handleRequest = auto handleRequest =
...@@ -291,7 +293,7 @@ TEST(Task, ContextPreservedAcrossMutexLock) { ...@@ -291,7 +293,7 @@ TEST(Task, ContextPreservedAcrossMutexLock) {
EXPECT_FALSE(t2.hasException()); EXPECT_FALSE(t2.hasException());
} }
TEST(Task, RequestContextSideEffectsArePreserved) { TEST_F(TaskTest, RequestContextSideEffectsArePreserved) {
auto f = auto f =
[&](folly::coro::Baton& baton) -> folly::coro::detail::InlineTask<void> { [&](folly::coro::Baton& baton) -> folly::coro::detail::InlineTask<void> {
RequestContext::create(); RequestContext::create();
...@@ -337,7 +339,7 @@ TEST(Task, RequestContextSideEffectsArePreserved) { ...@@ -337,7 +339,7 @@ TEST(Task, RequestContextSideEffectsArePreserved) {
EXPECT_FALSE(t.hasException()); EXPECT_FALSE(t.hasException());
} }
TEST(Task, FutureTailCall) { TEST_F(TaskTest, FutureTailCall) {
EXPECT_EQ( EXPECT_EQ(
42, 42,
folly::coro::blockingWait( folly::coro::blockingWait(
...@@ -361,14 +363,14 @@ folly::coro::Task<int&> returnIntRef(int& value) { ...@@ -361,14 +363,14 @@ folly::coro::Task<int&> returnIntRef(int& value) {
co_return value; co_return value;
} }
TEST(Task, TaskOfLvalueReference) { TEST_F(TaskTest, TaskOfLvalueReference) {
int value = 123; int value = 123;
auto&& result = folly::coro::blockingWait(returnIntRef(value)); auto&& result = folly::coro::blockingWait(returnIntRef(value));
static_assert(std::is_same_v<decltype(result), int&>); static_assert(std::is_same_v<decltype(result), int&>);
CHECK_EQ(&value, &result); CHECK_EQ(&value, &result);
} }
TEST(Task, TaskOfLvalueReferenceAsTry) { TEST_F(TaskTest, TaskOfLvalueReferenceAsTry) {
folly::coro::blockingWait([]() -> folly::coro::Task<void> { folly::coro::blockingWait([]() -> folly::coro::Task<void> {
int value = 123; int value = 123;
auto&& result = co_await co_awaitTry(returnIntRef(value)); auto&& result = co_await co_awaitTry(returnIntRef(value));
...@@ -380,7 +382,7 @@ TEST(Task, TaskOfLvalueReferenceAsTry) { ...@@ -380,7 +382,7 @@ TEST(Task, TaskOfLvalueReferenceAsTry) {
}()); }());
} }
TEST(Task, CancellationPropagation) { TEST_F(TaskTest, CancellationPropagation) {
folly::coro::blockingWait([]() -> folly::coro::Task<void> { folly::coro::blockingWait([]() -> folly::coro::Task<void> {
auto token = co_await folly::coro::co_current_cancellation_token; auto token = co_await folly::coro::co_current_cancellation_token;
CHECK(!token.canBeCancelled()); CHECK(!token.canBeCancelled());
...@@ -407,7 +409,7 @@ TEST(Task, CancellationPropagation) { ...@@ -407,7 +409,7 @@ TEST(Task, CancellationPropagation) {
}()); }());
} }
TEST(Task, StartInlineUnsafe) { TEST_F(TaskTest, StartInlineUnsafe) {
folly::coro::blockingWait([]() -> folly::coro::Task<void> { folly::coro::blockingWait([]() -> folly::coro::Task<void> {
auto executor = co_await folly::coro::co_current_executor; auto executor = co_await folly::coro::co_current_executor;
bool hasStarted = false; bool hasStarted = false;
......
...@@ -31,7 +31,9 @@ ...@@ -31,7 +31,9 @@
using namespace folly::coro; using namespace folly::coro;
TEST(Transform, SimpleStream) { class TransformTest : public testing::Test {};
TEST_F(TransformTest, SimpleStream) {
struct MyError : std::exception {}; struct MyError : std::exception {};
const float seenEndOfStream = 100.0f; const float seenEndOfStream = 100.0f;
...@@ -112,7 +114,7 @@ folly::coro::AsyncGenerator<Ref, Value> neverStream() { ...@@ -112,7 +114,7 @@ folly::coro::AsyncGenerator<Ref, Value> neverStream() {
co_await baton; co_await baton;
} }
TEST(Transform, CancellationTokenPropagatesFromConsumer) { TEST_F(TransformTest, CancellationTokenPropagatesFromConsumer) {
folly::coro::blockingWait([]() -> folly::coro::Task<void> { folly::coro::blockingWait([]() -> folly::coro::Task<void> {
folly::CancellationSource cancelSource; folly::CancellationSource cancelSource;
bool suspended = false; bool suspended = false;
......
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