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