Commit e652b1b2 authored by Cameron Pickett's avatar Cameron Pickett Committed by Facebook GitHub Bot

Cleanup CollectTest to use `EXPECT` instead of `CHECK`

Reviewed By: iahs

Differential Revision: D31266293

fbshipit-source-id: 99edca2496fd3764906e1c8483ff7cb1d3af0721
parent 9cad4956
...@@ -49,7 +49,7 @@ TEST_F(CollectAllTest, WithNoArgs) { ...@@ -49,7 +49,7 @@ TEST_F(CollectAllTest, WithNoArgs) {
completed = true; completed = true;
(void)result; (void)result;
}()); }());
CHECK(completed); EXPECT_TRUE(completed);
} }
TEST_F(CollectAllTest, OneTaskWithValue) { TEST_F(CollectAllTest, OneTaskWithValue) {
...@@ -62,7 +62,7 @@ TEST_F(CollectAllTest, OneTaskWithValue) { ...@@ -62,7 +62,7 @@ TEST_F(CollectAllTest, OneTaskWithValue) {
bool completed = false; bool completed = false;
auto run = [&]() -> folly::coro::Task<void> { auto run = [&]() -> folly::coro::Task<void> {
auto [result] = co_await folly::coro::collectAll(f()); auto [result] = co_await folly::coro::collectAll(f());
CHECK_EQ("hello", result); EXPECT_EQ("hello", result);
completed = true; completed = true;
}; };
...@@ -72,19 +72,19 @@ TEST_F(CollectAllTest, OneTaskWithValue) { ...@@ -72,19 +72,19 @@ TEST_F(CollectAllTest, OneTaskWithValue) {
executor.drain(); executor.drain();
CHECK(!completed); EXPECT_FALSE(completed);
baton.post(); baton.post();
// Posting the baton should have just scheduled the 'f()' coroutine // Posting the baton should have just scheduled the 'f()' coroutine
// for resumption on the executor but should not have executed // for resumption on the executor but should not have executed
// until we drain the executor again. // until we drain the executor again.
CHECK(!completed); EXPECT_FALSE(completed);
executor.drain(); executor.drain();
CHECK(completed); EXPECT_TRUE(completed);
CHECK(future.isReady()); EXPECT_TRUE(future.isReady());
} }
TEST_F(CollectAllTest, OneVoidTask) { TEST_F(CollectAllTest, OneVoidTask) {
...@@ -99,7 +99,7 @@ TEST_F(CollectAllTest, OneVoidTask) { ...@@ -99,7 +99,7 @@ TEST_F(CollectAllTest, OneVoidTask) {
}()); }());
(void)result; (void)result;
}()); }());
CHECK(completed); EXPECT_TRUE(completed);
} }
TEST_F(CollectAllTest, CollectAllDoesntCompleteUntilAllTasksComplete) { TEST_F(CollectAllTest, CollectAllDoesntCompleteUntilAllTasksComplete) {
...@@ -128,21 +128,21 @@ TEST_F(CollectAllTest, CollectAllDoesntCompleteUntilAllTasksComplete) { ...@@ -128,21 +128,21 @@ TEST_F(CollectAllTest, CollectAllDoesntCompleteUntilAllTasksComplete) {
auto future = run().scheduleOn(&executor).start(); auto future = run().scheduleOn(&executor).start();
CHECK(!task1Started); EXPECT_FALSE(task1Started);
CHECK(!task2Started); EXPECT_FALSE(task2Started);
executor.drain(); executor.drain();
CHECK(task1Started); EXPECT_TRUE(task1Started);
CHECK(task2Started); EXPECT_TRUE(task2Started);
CHECK(!complete); EXPECT_FALSE(complete);
baton1.post(); baton1.post();
executor.drain(); executor.drain();
CHECK(!complete); EXPECT_FALSE(complete);
baton2.post(); baton2.post();
executor.drain(); executor.drain();
CHECK(complete); EXPECT_TRUE(complete);
CHECK(future.isReady()); EXPECT_TRUE(future.isReady());
} }
struct ErrorA : std::exception {}; struct ErrorA : std::exception {};
...@@ -184,12 +184,12 @@ TEST_F(CollectAllTest, ThrowsFirstError) { ...@@ -184,12 +184,12 @@ TEST_F(CollectAllTest, ThrowsFirstError) {
(void)x; (void)x;
(void)y; (void)y;
(void)z; (void)z;
CHECK(false); ADD_FAILURE() << "Hit unexpected codepath";
} catch (const ErrorB&) { } catch (const ErrorB&) {
caughtException = true; caughtException = true;
} }
}()); }());
CHECK(caughtException); EXPECT_TRUE(caughtException);
} }
TEST_F(CollectAllTest, SynchronousCompletionInLoopDoesntCauseStackOverflow) { TEST_F(CollectAllTest, SynchronousCompletionInLoopDoesntCauseStackOverflow) {
...@@ -200,8 +200,8 @@ TEST_F(CollectAllTest, SynchronousCompletionInLoopDoesntCauseStackOverflow) { ...@@ -200,8 +200,8 @@ TEST_F(CollectAllTest, SynchronousCompletionInLoopDoesntCauseStackOverflow) {
auto [n, s] = co_await folly::coro::collectAll( auto [n, s] = co_await folly::coro::collectAll(
[]() -> folly::coro::Task<int> { co_return 123; }(), []() -> folly::coro::Task<int> { co_return 123; }(),
[]() -> folly::coro::Task<std::string> { co_return "abc"; }()); []() -> folly::coro::Task<std::string> { co_return "abc"; }());
CHECK_EQ(n, 123); EXPECT_EQ(n, 123);
CHECK_EQ(s, "abc"); EXPECT_EQ(s, "abc");
} }
}()); }());
} }
...@@ -245,7 +245,7 @@ TEST_F(CollectAllTest, ParallelAccumulate) { ...@@ -245,7 +245,7 @@ TEST_F(CollectAllTest, ParallelAccumulate) {
return std::max(a, b); return std::max(a, b);
}); });
CHECK_EQ(999'989, result); EXPECT_EQ(999'989, result);
}() }()
.scheduleOn(&threadPool)); .scheduleOn(&threadPool));
} }
...@@ -269,7 +269,7 @@ TEST_F(CollectAllTest, CollectAllCancelsSubtasksWhenASubtaskFails) { ...@@ -269,7 +269,7 @@ TEST_F(CollectAllTest, CollectAllCancelsSubtasksWhenASubtaskFails) {
co_await folly::coro::co_reschedule_on_current_executor; co_await folly::coro::co_reschedule_on_current_executor;
throw ErrorA{}; throw ErrorA{};
}()); }());
CHECK(false); ADD_FAILURE() << "Hit unexpected codepath";
(void)a; (void)a;
(void)b; (void)b;
(void)c; (void)c;
...@@ -277,7 +277,7 @@ TEST_F(CollectAllTest, CollectAllCancelsSubtasksWhenASubtaskFails) { ...@@ -277,7 +277,7 @@ TEST_F(CollectAllTest, CollectAllCancelsSubtasksWhenASubtaskFails) {
} }
auto end = std::chrono::steady_clock::now(); auto end = std::chrono::steady_clock::now();
CHECK((end - start) < 1s); EXPECT_LT(end - start, 1s);
}()); }());
} }
...@@ -306,9 +306,9 @@ TEST_F(CollectAllTest, CollectAllCancelsSubtasksWhenParentTaskCancelled) { ...@@ -306,9 +306,9 @@ TEST_F(CollectAllTest, CollectAllCancelsSubtasksWhenParentTaskCancelled) {
}())); }()));
auto end = std::chrono::steady_clock::now(); auto end = std::chrono::steady_clock::now();
CHECK((end - start) < 1s); EXPECT_LT(end - start, 1s);
CHECK_EQ(42, a); EXPECT_EQ(42, a);
CHECK_EQ(3.14f, b); EXPECT_EQ(3.14f, b);
(void)c; (void)c;
}()); }());
} }
...@@ -324,10 +324,10 @@ TEST_F(CollectAllTest, CancellationTokenRemainsActiveAfterReturn) { ...@@ -324,10 +324,10 @@ TEST_F(CollectAllTest, CancellationTokenRemainsActiveAfterReturn) {
scope.add( scope.add(
folly::coro::co_withCancellation( folly::coro::co_withCancellation(
token, folly::coro::co_invoke([&]() -> folly::coro::Task<void> { token, folly::coro::co_invoke([&]() -> folly::coro::Task<void> {
auto token = auto innerToken =
co_await folly::coro::co_current_cancellation_token; co_await folly::coro::co_current_cancellation_token;
co_await baton; co_await baton;
EXPECT_TRUE(token.isCancellationRequested()); EXPECT_TRUE(innerToken.isCancellationRequested());
})) }))
.scheduleOn(ex)); .scheduleOn(ex));
}); });
...@@ -368,22 +368,22 @@ TEST_F(CollectAllTest, CollectAllKeepsRequestContextOfChildTasksIndependent) { ...@@ -368,22 +368,22 @@ TEST_F(CollectAllTest, CollectAllKeepsRequestContextOfChildTasksIndependent) {
auto initialContextData = getContextData(); auto initialContextData = getContextData();
auto makeChildTask = [&]() -> folly::coro::Task<void> { auto makeChildTask = [&]() -> folly::coro::Task<void> {
CHECK(getContextData() == initialContextData); EXPECT_TRUE(getContextData() == initialContextData);
folly::RequestContextScopeGuard childScope; folly::RequestContextScopeGuard childScope;
CHECK(getContextData() == nullptr); EXPECT_TRUE(getContextData() == nullptr);
co_await folly::coro::co_reschedule_on_current_executor; co_await folly::coro::co_reschedule_on_current_executor;
CHECK(getContextData() == nullptr); EXPECT_TRUE(getContextData() == nullptr);
setContextData(); setContextData();
auto newContextData = getContextData(); auto newContextData = getContextData();
CHECK(newContextData != nullptr); EXPECT_TRUE(newContextData != nullptr);
CHECK(newContextData != initialContextData); EXPECT_TRUE(newContextData != initialContextData);
co_await folly::coro::co_reschedule_on_current_executor; co_await folly::coro::co_reschedule_on_current_executor;
CHECK(getContextData() == newContextData); EXPECT_TRUE(getContextData() == newContextData);
}; };
co_await folly::coro::collectAll(makeChildTask(), makeChildTask()); co_await folly::coro::collectAll(makeChildTask(), makeChildTask());
CHECK(getContextData() == initialContextData); EXPECT_TRUE(getContextData() == initialContextData);
}()); }());
} }
...@@ -397,8 +397,8 @@ TEST_F(CollectAllTest, TaskWithExecutorUsage) { ...@@ -397,8 +397,8 @@ TEST_F(CollectAllTest, TaskWithExecutorUsage) {
&threadPool), &threadPool),
[]() -> folly::coro::Task<std::string> { co_return "coroutine"; }() []() -> folly::coro::Task<std::string> { co_return "coroutine"; }()
.scheduleOn(&threadPool)); .scheduleOn(&threadPool));
CHECK(a == 42); EXPECT_TRUE(a == 42);
CHECK(b == "coroutine"); EXPECT_TRUE(b == "coroutine");
}()); }());
} }
...@@ -411,7 +411,7 @@ TEST_F(CollectAllTryTest, WithNoArgs) { ...@@ -411,7 +411,7 @@ TEST_F(CollectAllTryTest, WithNoArgs) {
completed = true; completed = true;
(void)result; (void)result;
}()); }());
CHECK(completed); EXPECT_TRUE(completed);
} }
TEST_F(CollectAllTryTest, OneTaskWithValue) { TEST_F(CollectAllTryTest, OneTaskWithValue) {
...@@ -424,7 +424,7 @@ TEST_F(CollectAllTryTest, OneTaskWithValue) { ...@@ -424,7 +424,7 @@ TEST_F(CollectAllTryTest, OneTaskWithValue) {
bool completed = false; bool completed = false;
auto run = [&]() -> folly::coro::Task<void> { auto run = [&]() -> folly::coro::Task<void> {
auto [result] = co_await folly::coro::collectAllTry(f()); auto [result] = co_await folly::coro::collectAllTry(f());
CHECK_EQ("hello", result.value()); EXPECT_EQ("hello", result.value());
completed = true; completed = true;
}; };
...@@ -434,19 +434,19 @@ TEST_F(CollectAllTryTest, OneTaskWithValue) { ...@@ -434,19 +434,19 @@ TEST_F(CollectAllTryTest, OneTaskWithValue) {
executor.drain(); executor.drain();
CHECK(!completed); EXPECT_FALSE(completed);
baton.post(); baton.post();
// Posting the baton should have just scheduled the 'f()' coroutine // Posting the baton should have just scheduled the 'f()' coroutine
// for resumption on the executor but should not have executed // for resumption on the executor but should not have executed
// until we drain the executor again. // until we drain the executor again.
CHECK(!completed); EXPECT_FALSE(completed);
executor.drain(); executor.drain();
CHECK(completed); EXPECT_TRUE(completed);
CHECK(future.isReady()); EXPECT_TRUE(future.isReady());
} }
TEST_F(CollectAllTryTest, OneTaskWithError) { TEST_F(CollectAllTryTest, OneTaskWithError) {
...@@ -458,9 +458,9 @@ TEST_F(CollectAllTryTest, OneTaskWithError) { ...@@ -458,9 +458,9 @@ TEST_F(CollectAllTryTest, OneTaskWithError) {
} }
throw ErrorA{}; throw ErrorA{};
}()); }());
CHECK(!result.hasValue()); EXPECT_FALSE(result.hasValue());
CHECK(result.hasException()); EXPECT_TRUE(result.hasException());
CHECK(result.exception().get_exception<ErrorA>() != nullptr); EXPECT_TRUE(result.exception().get_exception<ErrorA>() != nullptr);
}()); }());
} }
...@@ -481,10 +481,10 @@ TEST_F(CollectAllTryTest, PartialFailure) { ...@@ -481,10 +481,10 @@ TEST_F(CollectAllTryTest, PartialFailure) {
co_return; co_return;
}(), }(),
[]() -> folly::coro::Task<double> { co_return 3.1415; }()); []() -> folly::coro::Task<double> { co_return 3.1415; }());
CHECK(cRes.hasException()); EXPECT_TRUE(cRes.hasException());
CHECK(cRes.exception().get_exception<ErrorB>() != nullptr); EXPECT_TRUE(cRes.exception().get_exception<ErrorB>() != nullptr);
CHECK(dRes.hasValue()); EXPECT_TRUE(dRes.hasValue());
CHECK_EQ(3.1415, dRes.value()); EXPECT_EQ(3.1415, dRes.value());
}()); }());
} }
...@@ -499,8 +499,8 @@ TEST_F(CollectAllTryTest, CollectAllTryDoesNotCancelSubtasksWhenASubtaskFails) { ...@@ -499,8 +499,8 @@ TEST_F(CollectAllTryTest, CollectAllTryDoesNotCancelSubtasksWhenASubtaskFails) {
co_await folly::coro::co_reschedule_on_current_executor; co_await folly::coro::co_reschedule_on_current_executor;
co_await folly::coro::co_reschedule_on_current_executor; co_await folly::coro::co_reschedule_on_current_executor;
co_await folly::coro::co_reschedule_on_current_executor; co_await folly::coro::co_reschedule_on_current_executor;
CHECK(!(co_await folly::coro::co_current_cancellation_token) EXPECT_FALSE((co_await folly::coro::co_current_cancellation_token)
.isCancellationRequested()); .isCancellationRequested());
co_return 42; co_return 42;
}(), }(),
[]() -> folly::coro::Task<float> { []() -> folly::coro::Task<float> {
...@@ -509,8 +509,8 @@ TEST_F(CollectAllTryTest, CollectAllTryDoesNotCancelSubtasksWhenASubtaskFails) { ...@@ -509,8 +509,8 @@ TEST_F(CollectAllTryTest, CollectAllTryDoesNotCancelSubtasksWhenASubtaskFails) {
co_await folly::coro::co_reschedule_on_current_executor; co_await folly::coro::co_reschedule_on_current_executor;
co_await folly::coro::co_reschedule_on_current_executor; co_await folly::coro::co_reschedule_on_current_executor;
co_await folly::coro::co_reschedule_on_current_executor; co_await folly::coro::co_reschedule_on_current_executor;
CHECK(!(co_await folly::coro::co_current_cancellation_token) EXPECT_FALSE((co_await folly::coro::co_current_cancellation_token)
.isCancellationRequested()); .isCancellationRequested());
co_return 3.14f; co_return 3.14f;
}(), }(),
[]() -> folly::coro::Task<void> { []() -> folly::coro::Task<void> {
...@@ -518,11 +518,11 @@ TEST_F(CollectAllTryTest, CollectAllTryDoesNotCancelSubtasksWhenASubtaskFails) { ...@@ -518,11 +518,11 @@ TEST_F(CollectAllTryTest, CollectAllTryDoesNotCancelSubtasksWhenASubtaskFails) {
throw ErrorA{}; throw ErrorA{};
}()); }());
CHECK(a.hasValue()); EXPECT_TRUE(a.hasValue());
CHECK_EQ(42, a.value()); EXPECT_EQ(42, a.value());
CHECK(b.hasValue()); EXPECT_TRUE(b.hasValue());
CHECK_EQ(3.14f, b.value()); EXPECT_EQ(3.14f, b.value());
CHECK(c.hasException()); EXPECT_TRUE(c.hasException());
}()); }());
} }
...@@ -551,10 +551,10 @@ TEST_F(CollectAllTryTest, CollectAllCancelsSubtasksWhenParentTaskCancelled) { ...@@ -551,10 +551,10 @@ TEST_F(CollectAllTryTest, CollectAllCancelsSubtasksWhenParentTaskCancelled) {
}())); }()));
auto end = std::chrono::steady_clock::now(); auto end = std::chrono::steady_clock::now();
CHECK((end - start) < 1s); EXPECT_LT(end - start, 1s);
CHECK_EQ(42, a.value()); EXPECT_EQ(42, a.value());
CHECK_EQ(3.14f, b.value()); EXPECT_EQ(3.14f, b.value());
CHECK(c.hasValue()); EXPECT_TRUE(c.hasValue());
}()); }());
} }
...@@ -569,10 +569,10 @@ TEST_F(CollectAllTryTest, CancellationTokenRemainsActiveAfterReturn) { ...@@ -569,10 +569,10 @@ TEST_F(CollectAllTryTest, CancellationTokenRemainsActiveAfterReturn) {
scope.add( scope.add(
folly::coro::co_withCancellation( folly::coro::co_withCancellation(
token, folly::coro::co_invoke([&]() -> folly::coro::Task<void> { token, folly::coro::co_invoke([&]() -> folly::coro::Task<void> {
auto token = auto innerToken =
co_await folly::coro::co_current_cancellation_token; co_await folly::coro::co_current_cancellation_token;
co_await baton; co_await baton;
EXPECT_TRUE(token.isCancellationRequested()); EXPECT_TRUE(innerToken.isCancellationRequested());
})) }))
.scheduleOn(ex)); .scheduleOn(ex));
}); });
...@@ -602,22 +602,22 @@ TEST_F(CollectAllTryTest, KeepsRequestContextOfChildTasksIndependent) { ...@@ -602,22 +602,22 @@ TEST_F(CollectAllTryTest, KeepsRequestContextOfChildTasksIndependent) {
auto initialContextData = getContextData(); auto initialContextData = getContextData();
auto makeChildTask = [&]() -> folly::coro::Task<void> { auto makeChildTask = [&]() -> folly::coro::Task<void> {
CHECK(getContextData() == initialContextData); EXPECT_TRUE(getContextData() == initialContextData);
folly::RequestContextScopeGuard childScope; folly::RequestContextScopeGuard childScope;
CHECK(getContextData() == nullptr); EXPECT_TRUE(getContextData() == nullptr);
co_await folly::coro::co_reschedule_on_current_executor; co_await folly::coro::co_reschedule_on_current_executor;
CHECK(getContextData() == nullptr); EXPECT_TRUE(getContextData() == nullptr);
setContextData(); setContextData();
auto newContextData = getContextData(); auto newContextData = getContextData();
CHECK(newContextData != nullptr); EXPECT_TRUE(newContextData != nullptr);
CHECK(newContextData != initialContextData); EXPECT_TRUE(newContextData != initialContextData);
co_await folly::coro::co_reschedule_on_current_executor; co_await folly::coro::co_reschedule_on_current_executor;
CHECK(getContextData() == newContextData); EXPECT_TRUE(getContextData() == newContextData);
}; };
co_await folly::coro::collectAllTry(makeChildTask(), makeChildTask()); co_await folly::coro::collectAllTry(makeChildTask(), makeChildTask());
CHECK(getContextData() == initialContextData); EXPECT_TRUE(getContextData() == initialContextData);
}()); }());
} }
...@@ -650,7 +650,7 @@ TEST_F(CollectAllRangeTest, RangeOfVoidAllSucceeding) { ...@@ -650,7 +650,7 @@ TEST_F(CollectAllRangeTest, RangeOfVoidAllSucceeding) {
co_await folly::coro::collectAllRange(std::move(tasks)); co_await folly::coro::collectAllRange(std::move(tasks));
CHECK_EQ(3, count); EXPECT_EQ(3, count);
}()); }());
} }
...@@ -673,11 +673,11 @@ TEST_F(CollectAllRangeTest, RangeOfVoidSomeFailing) { ...@@ -673,11 +673,11 @@ TEST_F(CollectAllRangeTest, RangeOfVoidSomeFailing) {
try { try {
co_await folly::coro::collectAllRange(std::move(tasks)); co_await folly::coro::collectAllRange(std::move(tasks));
CHECK(false); ADD_FAILURE() << "Hit unexpected codepath";
} catch (const ErrorA&) { } catch (const ErrorA&) {
} }
CHECK_EQ(5, count); EXPECT_EQ(5, count);
}()); }());
} }
...@@ -700,16 +700,16 @@ TEST_F(CollectAllRangeTest, RangeOfNonVoid) { ...@@ -700,16 +700,16 @@ TEST_F(CollectAllRangeTest, RangeOfNonVoid) {
tasks.push_back(makeTask()); tasks.push_back(makeTask());
} }
CHECK_EQ(0, count); EXPECT_EQ(0, count);
std::vector<int> results = std::vector<int> results =
co_await folly::coro::collectAllRange(std::move(tasks)); co_await folly::coro::collectAllRange(std::move(tasks));
CHECK_EQ(taskCount, results.size()); EXPECT_EQ(taskCount, results.size());
CHECK_EQ(taskCount, count); EXPECT_EQ(taskCount, count);
for (int i = 0; i < taskCount; ++i) { for (int i = 0; i < taskCount; ++i) {
CHECK_EQ(i, results[i]); EXPECT_EQ(i, results[i]);
} }
}()); }());
} }
...@@ -740,13 +740,13 @@ TEST_F(CollectAllRangeTest, SubtasksCancelledWhenASubtaskFails) { ...@@ -740,13 +740,13 @@ TEST_F(CollectAllRangeTest, SubtasksCancelledWhenASubtaskFails) {
auto start = std::chrono::steady_clock::now(); auto start = std::chrono::steady_clock::now();
try { try {
co_await folly::coro::collectAllRange(generateTasks()); co_await folly::coro::collectAllRange(generateTasks());
CHECK(false); ADD_FAILURE() << "Hit unexpected codepath";
} catch (const ErrorA&) { } catch (const ErrorA&) {
} }
auto end = std::chrono::steady_clock::now(); auto end = std::chrono::steady_clock::now();
CHECK((end - start) < 1s); EXPECT_LT(end - start, 1s);
CHECK(consumedAllTasks); EXPECT_TRUE(consumedAllTasks);
}()); }());
} }
...@@ -768,7 +768,7 @@ TEST_F(CollectAllRangeTest, FailsWithErrorOfFirstTaskToFailWhenMultipleErrors) { ...@@ -768,7 +768,7 @@ TEST_F(CollectAllRangeTest, FailsWithErrorOfFirstTaskToFailWhenMultipleErrors) {
}(); }();
co_yield folly::coro::sleep(2s); co_yield folly::coro::sleep(2s);
}()); }());
CHECK(false); ADD_FAILURE() << "Hit unexpected codepath";
} catch (const ErrorB&) { } catch (const ErrorB&) {
} }
}()); }());
...@@ -795,7 +795,7 @@ TEST_F(CollectAllRangeTest, SubtasksCancelledWhenParentTaskCancelled) { ...@@ -795,7 +795,7 @@ TEST_F(CollectAllRangeTest, SubtasksCancelledWhenParentTaskCancelled) {
cancelSource.requestCancellation(); cancelSource.requestCancellation();
auto token = co_await folly::coro::co_current_cancellation_token; auto token = co_await folly::coro::co_current_cancellation_token;
CHECK(token.isCancellationRequested()); EXPECT_TRUE(token.isCancellationRequested());
}(); }();
consumedAllTasks = true; consumedAllTasks = true;
...@@ -806,8 +806,8 @@ TEST_F(CollectAllRangeTest, SubtasksCancelledWhenParentTaskCancelled) { ...@@ -806,8 +806,8 @@ TEST_F(CollectAllRangeTest, SubtasksCancelledWhenParentTaskCancelled) {
cancelSource.getToken(), folly::coro::collectAllRange(generateTasks())); cancelSource.getToken(), folly::coro::collectAllRange(generateTasks()));
auto end = std::chrono::steady_clock::now(); auto end = std::chrono::steady_clock::now();
CHECK((end - start) < 1s); EXPECT_LT(end - start, 1s);
CHECK(consumedAllTasks); EXPECT_TRUE(consumedAllTasks);
}()); }());
} }
...@@ -824,10 +824,10 @@ TEST_F(CollectAllRangeTest, CancellationTokenRemainsActiveAfterReturn) { ...@@ -824,10 +824,10 @@ TEST_F(CollectAllRangeTest, CancellationTokenRemainsActiveAfterReturn) {
scope.add( scope.add(
folly::coro::co_withCancellation( folly::coro::co_withCancellation(
token, folly::coro::co_invoke([&]() -> folly::coro::Task<void> { token, folly::coro::co_invoke([&]() -> folly::coro::Task<void> {
auto token = auto innerToken =
co_await folly::coro::co_current_cancellation_token; co_await folly::coro::co_current_cancellation_token;
co_await baton; co_await baton;
EXPECT_TRUE(token.isCancellationRequested()); EXPECT_TRUE(innerToken.isCancellationRequested());
})) }))
.scheduleOn(ex)); .scheduleOn(ex));
}); });
...@@ -858,17 +858,17 @@ TEST_F(CollectAllRangeTest, KeepsRequestContextOfChildTasksIndependent) { ...@@ -858,17 +858,17 @@ TEST_F(CollectAllRangeTest, KeepsRequestContextOfChildTasksIndependent) {
auto initialContextData = getContextData(); auto initialContextData = getContextData();
auto makeChildTask = [&]() -> folly::coro::Task<void> { auto makeChildTask = [&]() -> folly::coro::Task<void> {
CHECK(getContextData() == initialContextData); EXPECT_TRUE(getContextData() == initialContextData);
folly::RequestContextScopeGuard childScope; folly::RequestContextScopeGuard childScope;
CHECK(getContextData() == nullptr); EXPECT_TRUE(getContextData() == nullptr);
co_await folly::coro::co_reschedule_on_current_executor; co_await folly::coro::co_reschedule_on_current_executor;
CHECK(getContextData() == nullptr); EXPECT_TRUE(getContextData() == nullptr);
setContextData(); setContextData();
auto newContextData = getContextData(); auto newContextData = getContextData();
CHECK(newContextData != nullptr); EXPECT_TRUE(newContextData != nullptr);
CHECK(newContextData != initialContextData); EXPECT_TRUE(newContextData != initialContextData);
co_await folly::coro::co_reschedule_on_current_executor; co_await folly::coro::co_reschedule_on_current_executor;
CHECK(getContextData() == newContextData); EXPECT_TRUE(getContextData() == newContextData);
}; };
std::vector<folly::coro::Task<void>> tasks; std::vector<folly::coro::Task<void>> tasks;
...@@ -878,7 +878,7 @@ TEST_F(CollectAllRangeTest, KeepsRequestContextOfChildTasksIndependent) { ...@@ -878,7 +878,7 @@ TEST_F(CollectAllRangeTest, KeepsRequestContextOfChildTasksIndependent) {
co_await folly::coro::collectAllRange(std::move(tasks)); co_await folly::coro::collectAllRange(std::move(tasks));
CHECK(getContextData() == initialContextData); EXPECT_TRUE(getContextData() == initialContextData);
}()); }());
} }
...@@ -895,11 +895,11 @@ TEST_F(CollectAllRangeTest, VectorOfTaskWithExecutorUsage) { ...@@ -895,11 +895,11 @@ TEST_F(CollectAllRangeTest, VectorOfTaskWithExecutorUsage) {
} }
auto results = co_await folly::coro::collectAllRange(std::move(tasks)); auto results = co_await folly::coro::collectAllRange(std::move(tasks));
CHECK(results.size() == 4); EXPECT_TRUE(results.size() == 4);
CHECK(results[0] == 1); EXPECT_TRUE(results[0] == 1);
CHECK(results[1] == 2); EXPECT_TRUE(results[1] == 2);
CHECK(results[2] == 3); EXPECT_TRUE(results[2] == 3);
CHECK(results[3] == 4); EXPECT_TRUE(results[3] == 4);
}()); }());
} }
...@@ -1059,12 +1059,12 @@ TEST_F(CollectAllTryRangeTest, RangeOfVoidSomeFailing) { ...@@ -1059,12 +1059,12 @@ TEST_F(CollectAllTryRangeTest, RangeOfVoidSomeFailing) {
auto results = co_await folly::coro::collectAllTryRange(std::move(tasks)); auto results = co_await folly::coro::collectAllTryRange(std::move(tasks));
CHECK_EQ(5, results.size()); EXPECT_EQ(5, results.size());
CHECK(results[0].hasValue()); EXPECT_TRUE(results[0].hasValue());
CHECK(results[1].hasValue()); EXPECT_TRUE(results[1].hasValue());
CHECK(results[2].hasException()); EXPECT_TRUE(results[2].hasException());
CHECK(results[3].hasValue()); EXPECT_TRUE(results[3].hasValue());
CHECK(results[4].hasValue()); EXPECT_TRUE(results[4].hasValue());
}()); }());
} }
...@@ -1088,17 +1088,17 @@ TEST_F(CollectAllTryRangeTest, RangeOfValueSomeFailing) { ...@@ -1088,17 +1088,17 @@ TEST_F(CollectAllTryRangeTest, RangeOfValueSomeFailing) {
auto results = co_await folly::coro::collectAllTryRange(std::move(tasks)); auto results = co_await folly::coro::collectAllTryRange(std::move(tasks));
CHECK_EQ(6, results.size()); EXPECT_EQ(6, results.size());
CHECK(results[0].hasValue()); EXPECT_TRUE(results[0].hasValue());
CHECK_EQ("testing", results[0].value()); EXPECT_EQ("testing", results[0].value());
CHECK(results[1].hasValue()); EXPECT_TRUE(results[1].hasValue());
CHECK_EQ("testing", results[1].value()); EXPECT_EQ("testing", results[1].value());
CHECK(results[2].hasException()); EXPECT_TRUE(results[2].hasException());
CHECK(results[3].hasValue()); EXPECT_TRUE(results[3].hasValue());
CHECK_EQ("testing", results[3].value()); EXPECT_EQ("testing", results[3].value());
CHECK(results[4].hasValue()); EXPECT_TRUE(results[4].hasValue());
CHECK_EQ("testing", results[4].value()); EXPECT_EQ("testing", results[4].value());
CHECK(results[5].hasException()); EXPECT_TRUE(results[5].hasException());
}()); }());
} }
...@@ -1111,7 +1111,7 @@ TEST_F(CollectAllTryRangeTest, NotCancelledWhenSubtaskFails) { ...@@ -1111,7 +1111,7 @@ TEST_F(CollectAllTryRangeTest, NotCancelledWhenSubtaskFails) {
co_await folly::coro::co_reschedule_on_current_executor; co_await folly::coro::co_reschedule_on_current_executor;
co_await folly::coro::co_reschedule_on_current_executor; co_await folly::coro::co_reschedule_on_current_executor;
auto token = co_await folly::coro::co_current_cancellation_token; auto token = co_await folly::coro::co_current_cancellation_token;
CHECK(!token.isCancellationRequested()); EXPECT_FALSE(token.isCancellationRequested());
}; };
co_yield makeValidationTask(); co_yield makeValidationTask();
...@@ -1127,12 +1127,12 @@ TEST_F(CollectAllTryRangeTest, NotCancelledWhenSubtaskFails) { ...@@ -1127,12 +1127,12 @@ TEST_F(CollectAllTryRangeTest, NotCancelledWhenSubtaskFails) {
}; };
auto results = co_await folly::coro::collectAllTryRange(generateTasks()); auto results = co_await folly::coro::collectAllTryRange(generateTasks());
CHECK_EQ(5, results.size()); EXPECT_EQ(5, results.size());
CHECK(results[0].hasValue()); EXPECT_TRUE(results[0].hasValue());
CHECK(results[1].hasValue()); EXPECT_TRUE(results[1].hasValue());
CHECK(results[2].hasException()); EXPECT_TRUE(results[2].hasException());
CHECK(results[3].hasValue()); EXPECT_TRUE(results[3].hasValue());
CHECK(results[4].hasValue()); EXPECT_TRUE(results[4].hasValue());
}()); }());
} }
...@@ -1157,7 +1157,7 @@ TEST_F(CollectAllTryRangeTest, SubtasksCancelledWhenParentTaskCancelled) { ...@@ -1157,7 +1157,7 @@ TEST_F(CollectAllTryRangeTest, SubtasksCancelledWhenParentTaskCancelled) {
cancelSource.requestCancellation(); cancelSource.requestCancellation();
auto token = co_await folly::coro::co_current_cancellation_token; auto token = co_await folly::coro::co_current_cancellation_token;
CHECK(token.isCancellationRequested()); EXPECT_TRUE(token.isCancellationRequested());
}(); }();
consumedAllTasks = true; consumedAllTasks = true;
...@@ -1169,12 +1169,12 @@ TEST_F(CollectAllTryRangeTest, SubtasksCancelledWhenParentTaskCancelled) { ...@@ -1169,12 +1169,12 @@ TEST_F(CollectAllTryRangeTest, SubtasksCancelledWhenParentTaskCancelled) {
folly::coro::collectAllTryRange(generateTasks())); folly::coro::collectAllTryRange(generateTasks()));
auto end = std::chrono::steady_clock::now(); auto end = std::chrono::steady_clock::now();
CHECK_EQ(11, results.size()); EXPECT_EQ(11, results.size());
for (auto& result : results) { for (auto& result : results) {
CHECK(result.hasValue()); EXPECT_TRUE(result.hasValue());
} }
CHECK((end - start) < 1s); EXPECT_LT(end - start, 1s);
CHECK(consumedAllTasks); EXPECT_TRUE(consumedAllTasks);
}()); }());
} }
...@@ -1191,10 +1191,10 @@ TEST_F(CollectAllTryRangeTest, CancellationTokenRemainsActiveAfterReturn) { ...@@ -1191,10 +1191,10 @@ TEST_F(CollectAllTryRangeTest, CancellationTokenRemainsActiveAfterReturn) {
scope.add( scope.add(
folly::coro::co_withCancellation( folly::coro::co_withCancellation(
token, folly::coro::co_invoke([&]() -> folly::coro::Task<void> { token, folly::coro::co_invoke([&]() -> folly::coro::Task<void> {
auto token = auto innerToken =
co_await folly::coro::co_current_cancellation_token; co_await folly::coro::co_current_cancellation_token;
co_await baton; co_await baton;
EXPECT_TRUE(token.isCancellationRequested()); EXPECT_TRUE(innerToken.isCancellationRequested());
})) }))
.scheduleOn(ex)); .scheduleOn(ex));
}); });
...@@ -1226,17 +1226,17 @@ TEST_F(CollectAllTryRangeTest, KeepsRequestContextOfChildTasksIndependent) { ...@@ -1226,17 +1226,17 @@ TEST_F(CollectAllTryRangeTest, KeepsRequestContextOfChildTasksIndependent) {
auto initialContextData = getContextData(); auto initialContextData = getContextData();
auto makeChildTask = [&]() -> folly::coro::Task<void> { auto makeChildTask = [&]() -> folly::coro::Task<void> {
CHECK(getContextData() == initialContextData); EXPECT_TRUE(getContextData() == initialContextData);
folly::RequestContextScopeGuard childScope; folly::RequestContextScopeGuard childScope;
CHECK(getContextData() == nullptr); EXPECT_TRUE(getContextData() == nullptr);
co_await folly::coro::co_reschedule_on_current_executor; co_await folly::coro::co_reschedule_on_current_executor;
CHECK(getContextData() == nullptr); EXPECT_TRUE(getContextData() == nullptr);
setContextData(); setContextData();
auto newContextData = getContextData(); auto newContextData = getContextData();
CHECK(newContextData != nullptr); EXPECT_TRUE(newContextData != nullptr);
CHECK(newContextData != initialContextData); EXPECT_TRUE(newContextData != initialContextData);
co_await folly::coro::co_reschedule_on_current_executor; co_await folly::coro::co_reschedule_on_current_executor;
CHECK(getContextData() == newContextData); EXPECT_TRUE(getContextData() == newContextData);
}; };
std::vector<folly::coro::Task<void>> tasks; std::vector<folly::coro::Task<void>> tasks;
...@@ -1246,7 +1246,7 @@ TEST_F(CollectAllTryRangeTest, KeepsRequestContextOfChildTasksIndependent) { ...@@ -1246,7 +1246,7 @@ TEST_F(CollectAllTryRangeTest, KeepsRequestContextOfChildTasksIndependent) {
co_await folly::coro::collectAllTryRange(std::move(tasks)); co_await folly::coro::collectAllTryRange(std::move(tasks));
CHECK(getContextData() == initialContextData); EXPECT_TRUE(getContextData() == initialContextData);
}()); }());
} }
...@@ -1354,9 +1354,9 @@ TEST_F(CollectAllWindowedTest, ConcurrentTasks) { ...@@ -1354,9 +1354,9 @@ TEST_F(CollectAllWindowedTest, ConcurrentTasks) {
}(), }(),
10)); 10));
CHECK_EQ(10'000, results.size()); EXPECT_EQ(10'000, results.size());
for (int i = 0; i < 10'000; ++i) { for (int i = 0; i < 10'000; ++i) {
CHECK_EQ(folly::to<std::string>(i), results[i]); EXPECT_EQ(folly::to<std::string>(i), results[i]);
} }
} }
...@@ -1392,14 +1392,14 @@ TEST_F(CollectAllWindowedTest, WithGeneratorOfTaskOfValue) { ...@@ -1392,14 +1392,14 @@ TEST_F(CollectAllWindowedTest, WithGeneratorOfTaskOfValue) {
folly::coro::blockingWait([&]() -> folly::coro::Task<void> { folly::coro::blockingWait([&]() -> folly::coro::Task<void> {
auto results = co_await folly::coro::collectAllWindowed( auto results = co_await folly::coro::collectAllWindowed(
makeTaskGenerator(), maxConcurrency); makeTaskGenerator(), maxConcurrency);
CHECK_EQ(100, results.size()); EXPECT_EQ(100, results.size());
for (int i = 0; i < 100; ++i) { for (int i = 0; i < 100; ++i) {
CHECK_EQ(i, results[i]); EXPECT_EQ(i, results[i]);
} }
}()); }());
CHECK_EQ(0, activeCount.load()); EXPECT_EQ(0, activeCount.load());
CHECK_EQ(100, completedCount); EXPECT_EQ(100, completedCount);
} }
TEST_F(CollectAllWindowedTest, WithGeneratorOfTaskOfVoid) { TEST_F(CollectAllWindowedTest, WithGeneratorOfTaskOfVoid) {
...@@ -1428,8 +1428,8 @@ TEST_F(CollectAllWindowedTest, WithGeneratorOfTaskOfVoid) { ...@@ -1428,8 +1428,8 @@ TEST_F(CollectAllWindowedTest, WithGeneratorOfTaskOfVoid) {
makeTaskGenerator(), maxConcurrency); makeTaskGenerator(), maxConcurrency);
}()); }());
CHECK_EQ(0, activeCount.load()); EXPECT_EQ(0, activeCount.load());
CHECK_EQ(100, completedCount); EXPECT_EQ(100, completedCount);
} }
TEST_F(CollectAllWindowedTest, VectorOfVoidTask) { TEST_F(CollectAllWindowedTest, VectorOfVoidTask) {
...@@ -1449,7 +1449,7 @@ TEST_F(CollectAllWindowedTest, VectorOfVoidTask) { ...@@ -1449,7 +1449,7 @@ TEST_F(CollectAllWindowedTest, VectorOfVoidTask) {
folly::coro::blockingWait( folly::coro::blockingWait(
folly::coro::collectAllWindowed(std::move(tasks), 5)); folly::coro::collectAllWindowed(std::move(tasks), 5));
CHECK_EQ(10, count); EXPECT_EQ(10, count);
} }
TEST_F(CollectAllWindowedTest, VectorOfValueTask) { TEST_F(CollectAllWindowedTest, VectorOfValueTask) {
...@@ -1470,10 +1470,10 @@ TEST_F(CollectAllWindowedTest, VectorOfValueTask) { ...@@ -1470,10 +1470,10 @@ TEST_F(CollectAllWindowedTest, VectorOfValueTask) {
auto results = folly::coro::blockingWait( auto results = folly::coro::blockingWait(
folly::coro::collectAllWindowed(std::move(tasks), 5)); folly::coro::collectAllWindowed(std::move(tasks), 5));
CHECK_EQ(10, count); EXPECT_EQ(10, count);
CHECK_EQ(10, results.size()); EXPECT_EQ(10, results.size());
for (int i = 0; i < 10; ++i) { for (int i = 0; i < 10; ++i) {
CHECK_EQ(i, *results[i]); EXPECT_EQ(i, *results[i]);
} }
} }
...@@ -1498,7 +1498,7 @@ TEST_F(CollectAllWindowedTest, MultipleFailuresPropagatesFirstError) { ...@@ -1498,7 +1498,7 @@ TEST_F(CollectAllWindowedTest, MultipleFailuresPropagatesFirstError) {
} }
}(), }(),
5)); 5));
CHECK(false); // Should have thrown. ADD_FAILURE() << "Hit unexpected codepath"; // Should have thrown.
} catch (const ErrorB&) { } catch (const ErrorB&) {
// Expected. // Expected.
} }
...@@ -1526,13 +1526,13 @@ TEST_F(CollectAllWindowedTest, SubtasksCancelledWhenASubtaskFails) { ...@@ -1526,13 +1526,13 @@ TEST_F(CollectAllWindowedTest, SubtasksCancelledWhenASubtaskFails) {
auto start = std::chrono::steady_clock::now(); auto start = std::chrono::steady_clock::now();
try { try {
co_await folly::coro::collectAllWindowed(generateTasks(), 2); co_await folly::coro::collectAllWindowed(generateTasks(), 2);
CHECK(false); ADD_FAILURE() << "Hit unexpected codepath";
} catch (const ErrorA&) { } catch (const ErrorA&) {
} }
auto end = std::chrono::steady_clock::now(); auto end = std::chrono::steady_clock::now();
CHECK((end - start) < 1s); EXPECT_LT(end - start, 1s);
CHECK(consumedAllTasks); EXPECT_TRUE(consumedAllTasks);
}()); }());
} }
...@@ -1556,7 +1556,7 @@ TEST_F(CollectAllWindowedTest, SubtasksCancelledWhenParentTaskCancelled) { ...@@ -1556,7 +1556,7 @@ TEST_F(CollectAllWindowedTest, SubtasksCancelledWhenParentTaskCancelled) {
cancelSource.requestCancellation(); cancelSource.requestCancellation();
auto token = co_await folly::coro::co_current_cancellation_token; auto token = co_await folly::coro::co_current_cancellation_token;
CHECK(token.isCancellationRequested()); EXPECT_TRUE(token.isCancellationRequested());
}(); }();
co_yield sleepThatShouldBeCancelled(10s); co_yield sleepThatShouldBeCancelled(10s);
...@@ -1571,8 +1571,8 @@ TEST_F(CollectAllWindowedTest, SubtasksCancelledWhenParentTaskCancelled) { ...@@ -1571,8 +1571,8 @@ TEST_F(CollectAllWindowedTest, SubtasksCancelledWhenParentTaskCancelled) {
folly::coro::collectAllWindowed(generateTasks(), 4)); folly::coro::collectAllWindowed(generateTasks(), 4));
auto end = std::chrono::steady_clock::now(); auto end = std::chrono::steady_clock::now();
CHECK((end - start) < 1s); EXPECT_LT(end - start, 1s);
CHECK(consumedAllTasks); EXPECT_TRUE(consumedAllTasks);
}()); }());
} }
...@@ -1589,10 +1589,10 @@ TEST_F(CollectAllWindowedTest, CancellationTokenRemainsActiveAfterReturn) { ...@@ -1589,10 +1589,10 @@ TEST_F(CollectAllWindowedTest, CancellationTokenRemainsActiveAfterReturn) {
scope.add( scope.add(
folly::coro::co_withCancellation( folly::coro::co_withCancellation(
token, folly::coro::co_invoke([&]() -> folly::coro::Task<void> { token, folly::coro::co_invoke([&]() -> folly::coro::Task<void> {
auto token = auto innerToken =
co_await folly::coro::co_current_cancellation_token; co_await folly::coro::co_current_cancellation_token;
co_await baton; co_await baton;
EXPECT_TRUE(token.isCancellationRequested()); EXPECT_TRUE(innerToken.isCancellationRequested());
})) }))
.scheduleOn(ex)); .scheduleOn(ex));
}); });
...@@ -1624,17 +1624,17 @@ TEST_F(CollectAllWindowedTest, KeepsRequestContextOfChildTasksIndependent) { ...@@ -1624,17 +1624,17 @@ TEST_F(CollectAllWindowedTest, KeepsRequestContextOfChildTasksIndependent) {
auto initialContextData = getContextData(); auto initialContextData = getContextData();
auto makeChildTask = [&]() -> folly::coro::Task<void> { auto makeChildTask = [&]() -> folly::coro::Task<void> {
CHECK(getContextData() == initialContextData); EXPECT_TRUE(getContextData() == initialContextData);
folly::RequestContextScopeGuard childScope; folly::RequestContextScopeGuard childScope;
CHECK(getContextData() == nullptr); EXPECT_TRUE(getContextData() == nullptr);
co_await folly::coro::co_reschedule_on_current_executor; co_await folly::coro::co_reschedule_on_current_executor;
CHECK(getContextData() == nullptr); EXPECT_TRUE(getContextData() == nullptr);
setContextData(); setContextData();
auto newContextData = getContextData(); auto newContextData = getContextData();
CHECK(newContextData != nullptr); EXPECT_TRUE(newContextData != nullptr);
CHECK(newContextData != initialContextData); EXPECT_TRUE(newContextData != initialContextData);
co_await folly::coro::co_reschedule_on_current_executor; co_await folly::coro::co_reschedule_on_current_executor;
CHECK(getContextData() == newContextData); EXPECT_TRUE(getContextData() == newContextData);
}; };
std::vector<folly::coro::Task<void>> tasks; std::vector<folly::coro::Task<void>> tasks;
...@@ -1644,7 +1644,7 @@ TEST_F(CollectAllWindowedTest, KeepsRequestContextOfChildTasksIndependent) { ...@@ -1644,7 +1644,7 @@ TEST_F(CollectAllWindowedTest, KeepsRequestContextOfChildTasksIndependent) {
co_await folly::coro::collectAllWindowed(std::move(tasks), 2); co_await folly::coro::collectAllWindowed(std::move(tasks), 2);
CHECK(getContextData() == initialContextData); EXPECT_TRUE(getContextData() == initialContextData);
}()); }());
} }
...@@ -1662,11 +1662,11 @@ TEST_F(CollectAllWindowedTest, VectorOfTaskWithExecutorUsage) { ...@@ -1662,11 +1662,11 @@ TEST_F(CollectAllWindowedTest, VectorOfTaskWithExecutorUsage) {
auto results = auto results =
co_await folly::coro::collectAllWindowed(std::move(tasks), 2); co_await folly::coro::collectAllWindowed(std::move(tasks), 2);
CHECK(results.size() == 4); EXPECT_TRUE(results.size() == 4);
CHECK(results[0] == 1); EXPECT_TRUE(results[0] == 1);
CHECK(results[1] == 2); EXPECT_TRUE(results[1] == 2);
CHECK(results[2] == 3); EXPECT_TRUE(results[2] == 3);
CHECK(results[3] == 4); EXPECT_TRUE(results[3] == 4);
}()); }());
} }
...@@ -1691,18 +1691,18 @@ TEST_F(CollectAllTryWindowedTest, PartialFailure) { ...@@ -1691,18 +1691,18 @@ TEST_F(CollectAllTryWindowedTest, PartialFailure) {
} }
}(), }(),
5)); 5));
CHECK_EQ(10, results.size()); EXPECT_EQ(10, results.size());
for (int i = 0; i < 10; ++i) { for (int i = 0; i < 10; ++i) {
if (i == 3) { if (i == 3) {
CHECK(results[i].hasException()); EXPECT_TRUE(results[i].hasException());
CHECK(results[i].exception().is_compatible_with<ErrorA>()); EXPECT_TRUE(results[i].exception().is_compatible_with<ErrorA>());
} else if (i == 7) { } else if (i == 7) {
CHECK(results[i].hasException()); EXPECT_TRUE(results[i].hasException());
CHECK(results[i].exception().is_compatible_with<ErrorB>()); EXPECT_TRUE(results[i].exception().is_compatible_with<ErrorB>());
} else { } else {
CHECK(results[i].hasValue()); EXPECT_TRUE(results[i].hasValue());
CHECK_EQ(i, results[i].value()); EXPECT_EQ(i, results[i].value());
} }
} }
} }
...@@ -1730,14 +1730,14 @@ TEST_F(CollectAllTryWindowedTest, GeneratorFailure) { ...@@ -1730,14 +1730,14 @@ TEST_F(CollectAllTryWindowedTest, GeneratorFailure) {
try { try {
[[maybe_unused]] auto results = folly::coro::blockingWait( [[maybe_unused]] auto results = folly::coro::blockingWait(
folly::coro::collectAllTryWindowed(generateTasks(), 5)); folly::coro::collectAllTryWindowed(generateTasks(), 5));
CHECK(false); ADD_FAILURE() << "Hit unexpected codepath";
} catch (const ErrorA&) { } catch (const ErrorA&) {
} }
// Even if the generator throws an exception we should still have launched // Even if the generator throws an exception we should still have launched
// and waited for completion all of the prior tasks in the sequence. // and waited for completion all of the prior tasks in the sequence.
CHECK_EQ(10, started); EXPECT_EQ(10, started);
CHECK_EQ(0, active); EXPECT_EQ(0, active);
} }
TEST_F(CollectAllTryWindowedTest, NotCancelledWhenSubtaskFails) { TEST_F(CollectAllTryWindowedTest, NotCancelledWhenSubtaskFails) {
...@@ -1754,7 +1754,7 @@ TEST_F(CollectAllTryWindowedTest, NotCancelledWhenSubtaskFails) { ...@@ -1754,7 +1754,7 @@ TEST_F(CollectAllTryWindowedTest, NotCancelledWhenSubtaskFails) {
co_await folly::coro::co_reschedule_on_current_executor; co_await folly::coro::co_reschedule_on_current_executor;
co_await folly::coro::co_reschedule_on_current_executor; co_await folly::coro::co_reschedule_on_current_executor;
auto token = co_await folly::coro::co_current_cancellation_token; auto token = co_await folly::coro::co_current_cancellation_token;
CHECK(!token.isCancellationRequested()); EXPECT_FALSE(token.isCancellationRequested());
}; };
co_yield makeValidationTask(); co_yield makeValidationTask();
...@@ -1763,10 +1763,10 @@ TEST_F(CollectAllTryWindowedTest, NotCancelledWhenSubtaskFails) { ...@@ -1763,10 +1763,10 @@ TEST_F(CollectAllTryWindowedTest, NotCancelledWhenSubtaskFails) {
auto results = auto results =
co_await folly::coro::collectAllTryWindowed(generateTasks(), 2); co_await folly::coro::collectAllTryWindowed(generateTasks(), 2);
CHECK_EQ(3, results.size()); EXPECT_EQ(3, results.size());
CHECK(results[0].hasException()); EXPECT_TRUE(results[0].hasException());
CHECK(results[1].hasValue()); EXPECT_TRUE(results[1].hasValue());
CHECK(results[2].hasValue()); EXPECT_TRUE(results[2].hasValue());
}()); }());
} }
...@@ -1790,7 +1790,7 @@ TEST_F(CollectAllTryWindowedTest, SubtasksCancelledWhenParentTaskCancelled) { ...@@ -1790,7 +1790,7 @@ TEST_F(CollectAllTryWindowedTest, SubtasksCancelledWhenParentTaskCancelled) {
cancelSource.requestCancellation(); cancelSource.requestCancellation();
auto token = co_await folly::coro::co_current_cancellation_token; auto token = co_await folly::coro::co_current_cancellation_token;
CHECK(token.isCancellationRequested()); EXPECT_TRUE(token.isCancellationRequested());
}(); }();
co_yield sleepThatShouldBeCancelled(10s); co_yield sleepThatShouldBeCancelled(10s);
...@@ -1805,12 +1805,12 @@ TEST_F(CollectAllTryWindowedTest, SubtasksCancelledWhenParentTaskCancelled) { ...@@ -1805,12 +1805,12 @@ TEST_F(CollectAllTryWindowedTest, SubtasksCancelledWhenParentTaskCancelled) {
folly::coro::collectAllTryWindowed(generateTasks(), 4)); folly::coro::collectAllTryWindowed(generateTasks(), 4));
auto end = std::chrono::steady_clock::now(); auto end = std::chrono::steady_clock::now();
CHECK_EQ(5, results.size()); EXPECT_EQ(5, results.size());
for (auto& result : results) { for (auto& result : results) {
CHECK(result.hasValue()); EXPECT_TRUE(result.hasValue());
} }
CHECK((end - start) < 1s); EXPECT_LT(end - start, 1s);
CHECK(consumedAllTasks); EXPECT_TRUE(consumedAllTasks);
}()); }());
} }
...@@ -1827,10 +1827,10 @@ TEST_F(CollectAllTryWindowedTest, CancellationTokenRemainsActiveAfterReturn) { ...@@ -1827,10 +1827,10 @@ TEST_F(CollectAllTryWindowedTest, CancellationTokenRemainsActiveAfterReturn) {
scope.add( scope.add(
folly::coro::co_withCancellation( folly::coro::co_withCancellation(
token, folly::coro::co_invoke([&]() -> folly::coro::Task<void> { token, folly::coro::co_invoke([&]() -> folly::coro::Task<void> {
auto token = auto innerToken =
co_await folly::coro::co_current_cancellation_token; co_await folly::coro::co_current_cancellation_token;
co_await baton; co_await baton;
EXPECT_TRUE(token.isCancellationRequested()); EXPECT_TRUE(innerToken.isCancellationRequested());
})) }))
.scheduleOn(ex)); .scheduleOn(ex));
}); });
...@@ -1857,8 +1857,8 @@ TEST_F(CollectAnyTest, OneTaskWithValue) { ...@@ -1857,8 +1857,8 @@ TEST_F(CollectAnyTest, OneTaskWithValue) {
bool completed = false; bool completed = false;
auto run = [&]() -> folly::coro::Task<void> { auto run = [&]() -> folly::coro::Task<void> {
auto [index, result] = co_await folly::coro::collectAny(f()); auto [index, result] = co_await folly::coro::collectAny(f());
CHECK_EQ("hello", result.value()); EXPECT_EQ("hello", result.value());
CHECK_EQ(0, index); EXPECT_EQ(0, index);
completed = true; completed = true;
}; };
...@@ -1868,19 +1868,19 @@ TEST_F(CollectAnyTest, OneTaskWithValue) { ...@@ -1868,19 +1868,19 @@ TEST_F(CollectAnyTest, OneTaskWithValue) {
executor.drain(); executor.drain();
CHECK(!completed); EXPECT_FALSE(completed);
baton.post(); baton.post();
// Posting the baton should have just scheduled the 'f()' coroutine // Posting the baton should have just scheduled the 'f()' coroutine
// for resumption on the executor but should not have executed // for resumption on the executor but should not have executed
// until we drain the executor again. // until we drain the executor again.
CHECK(!completed); EXPECT_FALSE(completed);
executor.drain(); executor.drain();
CHECK(completed); EXPECT_TRUE(completed);
CHECK(future.isReady()); EXPECT_TRUE(future.isReady());
} }
TEST_F(CollectAnyTest, OneVoidTask) { TEST_F(CollectAnyTest, OneVoidTask) {
...@@ -1895,7 +1895,7 @@ TEST_F(CollectAnyTest, OneVoidTask) { ...@@ -1895,7 +1895,7 @@ TEST_F(CollectAnyTest, OneVoidTask) {
}()); }());
(void)result; (void)result;
}()); }());
CHECK(completed); EXPECT_TRUE(completed);
} }
TEST_F(CollectAnyTest, MoveOnlyType) { TEST_F(CollectAnyTest, MoveOnlyType) {
...@@ -1911,7 +1911,7 @@ TEST_F(CollectAnyTest, MoveOnlyType) { ...@@ -1911,7 +1911,7 @@ TEST_F(CollectAnyTest, MoveOnlyType) {
}()); }());
(void)result; (void)result;
}()); }());
CHECK(completed); EXPECT_TRUE(completed);
} }
TEST_F(CollectAnyTest, CollectAnyDoesntCompleteUntilAllTasksComplete) { TEST_F(CollectAnyTest, CollectAnyDoesntCompleteUntilAllTasksComplete) {
...@@ -1935,29 +1935,29 @@ TEST_F(CollectAnyTest, CollectAnyDoesntCompleteUntilAllTasksComplete) { ...@@ -1935,29 +1935,29 @@ TEST_F(CollectAnyTest, CollectAnyDoesntCompleteUntilAllTasksComplete) {
co_return 314; co_return 314;
}()); }());
complete = true; complete = true;
CHECK_EQ(taskTerminatingExpectedIndex, index); EXPECT_EQ(taskTerminatingExpectedIndex, index);
CHECK_EQ(result.value(), 314); EXPECT_EQ(result.value(), 314);
}; };
folly::ManualExecutor executor; folly::ManualExecutor executor;
auto future = run().scheduleOn(&executor).start(); auto future = run().scheduleOn(&executor).start();
CHECK(!task1Started); EXPECT_FALSE(task1Started);
CHECK(!task2Started); EXPECT_FALSE(task2Started);
executor.drain(); executor.drain();
CHECK(task1Started); EXPECT_TRUE(task1Started);
CHECK(task2Started); EXPECT_TRUE(task2Started);
CHECK(!complete); EXPECT_FALSE(complete);
baton2.post(); baton2.post();
executor.drain(); executor.drain();
CHECK(!complete); EXPECT_FALSE(complete);
baton1.post(); baton1.post();
executor.drain(); executor.drain();
CHECK(complete); EXPECT_TRUE(complete);
CHECK(future.isReady()); EXPECT_TRUE(future.isReady());
} }
TEST_F(CollectAnyTest, ThrowsFirstError) { TEST_F(CollectAnyTest, ThrowsFirstError) {
...@@ -1991,15 +1991,15 @@ TEST_F(CollectAnyTest, ThrowsFirstError) { ...@@ -1991,15 +1991,15 @@ TEST_F(CollectAnyTest, ThrowsFirstError) {
} }
co_return 3; co_return 3;
}()); }());
CHECK_EQ(1, index); EXPECT_EQ(1, index);
try { try {
result.value(); result.value();
CHECK(false); ADD_FAILURE() << "Hit unexpected codepath";
} catch (const ErrorB&) { } catch (const ErrorB&) {
caughtException = true; caughtException = true;
} }
}()); }());
CHECK(caughtException); EXPECT_TRUE(caughtException);
} }
TEST_F(CollectAnyTest, CollectAnyCancelsSubtasksWhenASubtaskCompletes) { TEST_F(CollectAnyTest, CollectAnyCancelsSubtasksWhenASubtaskCompletes) {
...@@ -2021,15 +2021,15 @@ TEST_F(CollectAnyTest, CollectAnyCancelsSubtasksWhenASubtaskCompletes) { ...@@ -2021,15 +2021,15 @@ TEST_F(CollectAnyTest, CollectAnyCancelsSubtasksWhenASubtaskCompletes) {
co_await folly::coro::co_reschedule_on_current_executor; co_await folly::coro::co_reschedule_on_current_executor;
throw ErrorA{}; throw ErrorA{};
}()); }());
CHECK_EQ(2, index); EXPECT_EQ(2, index);
try { try {
result.value(); result.value();
CHECK(false); ADD_FAILURE() << "Hit unexpected codepath";
} catch (const ErrorA&) { } catch (const ErrorA&) {
} }
auto end = std::chrono::steady_clock::now(); auto end = std::chrono::steady_clock::now();
CHECK((end - start) < 1s); EXPECT_LT(end - start, 1s);
}()); }());
} }
...@@ -2059,10 +2059,10 @@ TEST_F(CollectAnyTest, CollectAnyCancelsSubtasksWhenParentTaskCancelled) { ...@@ -2059,10 +2059,10 @@ TEST_F(CollectAnyTest, CollectAnyCancelsSubtasksWhenParentTaskCancelled) {
co_await sleepThatShouldBeCancelled(15s); co_await sleepThatShouldBeCancelled(15s);
co_return 123; co_return 123;
}())); }()));
CHECK(false); ADD_FAILURE() << "Hit unexpected codepath";
} catch (const folly::OperationCancelled&) { } catch (const folly::OperationCancelled&) {
auto end = std::chrono::steady_clock::now(); auto end = std::chrono::steady_clock::now();
CHECK((end - start) < 1s); EXPECT_LT(end - start, 1s);
} }
}()); }());
} }
...@@ -2078,10 +2078,10 @@ TEST_F(CollectAnyTest, CancellationTokenRemainsActiveAfterReturn) { ...@@ -2078,10 +2078,10 @@ TEST_F(CollectAnyTest, CancellationTokenRemainsActiveAfterReturn) {
scope.add( scope.add(
folly::coro::co_withCancellation( folly::coro::co_withCancellation(
token, folly::coro::co_invoke([&]() -> folly::coro::Task<void> { token, folly::coro::co_invoke([&]() -> folly::coro::Task<void> {
auto token = auto innerToken =
co_await folly::coro::co_current_cancellation_token; co_await folly::coro::co_current_cancellation_token;
co_await baton; co_await baton;
EXPECT_TRUE(token.isCancellationRequested()); EXPECT_TRUE(innerToken.isCancellationRequested());
})) }))
.scheduleOn(ex)); .scheduleOn(ex));
}); });
...@@ -2104,10 +2104,10 @@ TEST_F(CollectAnyNoDiscardTest, OneTask) { ...@@ -2104,10 +2104,10 @@ TEST_F(CollectAnyNoDiscardTest, OneTask) {
folly::coro::blockingWait([&]() -> folly::coro::Task<void> { folly::coro::blockingWait([&]() -> folly::coro::Task<void> {
auto [result] = co_await folly::coro::collectAnyNoDiscard(value()); auto [result] = co_await folly::coro::collectAnyNoDiscard(value());
CHECK(result.hasValue()); EXPECT_TRUE(result.hasValue());
CHECK_EQ("hello", result.value()); EXPECT_EQ("hello", result.value());
std::tie(result) = co_await folly::coro::collectAnyNoDiscard(throws()); std::tie(result) = co_await folly::coro::collectAnyNoDiscard(throws());
CHECK(result.hasException<ErrorA>()); EXPECT_TRUE(result.hasException<ErrorA>());
}()); }());
} }
...@@ -2128,9 +2128,9 @@ TEST_F(CollectAnyNoDiscardTest, MultipleTasksWithValues) { ...@@ -2128,9 +2128,9 @@ TEST_F(CollectAnyNoDiscardTest, MultipleTasksWithValues) {
folly::coro::blockingWait([&]() -> folly::coro::Task<void> { folly::coro::blockingWait([&]() -> folly::coro::Task<void> {
auto [first, second, third] = co_await folly::coro::collectAnyNoDiscard( auto [first, second, third] = co_await folly::coro::collectAnyNoDiscard(
busyWait(count, 3), busyWait(count, 3), busyWait(count, 3)); busyWait(count, 3), busyWait(count, 3), busyWait(count, 3));
CHECK(first.hasValue()); EXPECT_TRUE(first.hasValue());
CHECK(second.hasValue()); EXPECT_TRUE(second.hasValue());
CHECK(third.hasValue()); EXPECT_TRUE(third.hasValue());
}()); }());
} }
...@@ -2147,7 +2147,7 @@ TEST_F(CollectAnyNoDiscardTest, OneVoidTask) { ...@@ -2147,7 +2147,7 @@ TEST_F(CollectAnyNoDiscardTest, OneVoidTask) {
}()); }());
(void)result; (void)result;
}()); }());
CHECK(completed); EXPECT_TRUE(completed);
} }
TEST_F(CollectAnyNoDiscardTest, DoesntCompleteUntilAllTasksComplete) { TEST_F(CollectAnyNoDiscardTest, DoesntCompleteUntilAllTasksComplete) {
...@@ -2170,31 +2170,31 @@ TEST_F(CollectAnyNoDiscardTest, DoesntCompleteUntilAllTasksComplete) { ...@@ -2170,31 +2170,31 @@ TEST_F(CollectAnyNoDiscardTest, DoesntCompleteUntilAllTasksComplete) {
co_return 314; co_return 314;
}()); }());
complete = true; complete = true;
CHECK(first.hasValue()); EXPECT_TRUE(first.hasValue());
CHECK_EQ(first.value(), 42); EXPECT_EQ(first.value(), 42);
CHECK(second.hasValue()); EXPECT_TRUE(second.hasValue());
CHECK_EQ(second.value(), 314); EXPECT_EQ(second.value(), 314);
}; };
folly::ManualExecutor executor; folly::ManualExecutor executor;
auto future = run().scheduleOn(&executor).start(); auto future = run().scheduleOn(&executor).start();
CHECK(!task1Started); EXPECT_FALSE(task1Started);
CHECK(!task2Started); EXPECT_FALSE(task2Started);
executor.drain(); executor.drain();
CHECK(task1Started); EXPECT_TRUE(task1Started);
CHECK(task2Started); EXPECT_TRUE(task2Started);
CHECK(!complete); EXPECT_FALSE(complete);
baton2.post(); baton2.post();
executor.drain(); executor.drain();
CHECK(!complete); EXPECT_FALSE(complete);
baton1.post(); baton1.post();
executor.drain(); executor.drain();
CHECK(complete); EXPECT_TRUE(complete);
CHECK(future.isReady()); EXPECT_TRUE(future.isReady());
} }
TEST_F(CollectAnyNoDiscardTest, ThrowsAllErrors) { TEST_F(CollectAnyNoDiscardTest, ThrowsAllErrors) {
...@@ -2217,9 +2217,9 @@ TEST_F(CollectAnyNoDiscardTest, ThrowsAllErrors) { ...@@ -2217,9 +2217,9 @@ TEST_F(CollectAnyNoDiscardTest, ThrowsAllErrors) {
[&]() -> folly::coro::Task<int> { [&]() -> folly::coro::Task<int> {
co_yield folly::coro::co_error(ErrorC{}); co_yield folly::coro::co_error(ErrorC{});
}()); }());
CHECK(first.hasException<ErrorA>()); EXPECT_TRUE(first.hasException<ErrorA>());
CHECK(second.hasException<ErrorB>()); EXPECT_TRUE(second.hasException<ErrorB>());
CHECK(third.hasException<ErrorC>()); EXPECT_TRUE(third.hasException<ErrorC>());
}()); }());
} }
...@@ -2242,13 +2242,13 @@ TEST_F(CollectAnyNoDiscardTest, CancelSubtasksWhenASubtaskCompletes) { ...@@ -2242,13 +2242,13 @@ TEST_F(CollectAnyNoDiscardTest, CancelSubtasksWhenASubtaskCompletes) {
co_await folly::coro::co_reschedule_on_current_executor; co_await folly::coro::co_reschedule_on_current_executor;
co_yield folly::coro::co_error(ErrorA{}); co_yield folly::coro::co_error(ErrorA{});
}()); }());
CHECK(first.hasException<folly::OperationCancelled>()); EXPECT_TRUE(first.hasException<folly::OperationCancelled>());
CHECK(second.hasException<folly::OperationCancelled>()); EXPECT_TRUE(second.hasException<folly::OperationCancelled>());
CHECK(third.hasException<ErrorA>()); EXPECT_TRUE(third.hasException<ErrorA>());
auto end = std::chrono::steady_clock::now(); auto end = std::chrono::steady_clock::now();
CHECK((end - start) < 1s); EXPECT_LT(end - start, 1s);
}()); }());
} }
...@@ -2278,10 +2278,10 @@ TEST_F(CollectAnyNoDiscardTest, CancelSubtasksWhenParentTaskCancelled) { ...@@ -2278,10 +2278,10 @@ TEST_F(CollectAnyNoDiscardTest, CancelSubtasksWhenParentTaskCancelled) {
co_return 123; co_return 123;
}())); }()));
auto end = std::chrono::steady_clock::now(); auto end = std::chrono::steady_clock::now();
CHECK((end - start) < 1s); EXPECT_LT(end - start, 1s);
CHECK(first.hasException<folly::OperationCancelled>()); EXPECT_TRUE(first.hasException<folly::OperationCancelled>());
CHECK(second.hasException<folly::OperationCancelled>()); EXPECT_TRUE(second.hasException<folly::OperationCancelled>());
CHECK(third.hasException<folly::OperationCancelled>()); EXPECT_TRUE(third.hasException<folly::OperationCancelled>());
}()); }());
} }
...@@ -2296,10 +2296,10 @@ TEST_F(CollectAnyNoDiscardTest, CancellationTokenRemainsActiveAfterReturn) { ...@@ -2296,10 +2296,10 @@ TEST_F(CollectAnyNoDiscardTest, CancellationTokenRemainsActiveAfterReturn) {
scope.add( scope.add(
folly::coro::co_withCancellation( folly::coro::co_withCancellation(
token, folly::coro::co_invoke([&]() -> folly::coro::Task<void> { token, folly::coro::co_invoke([&]() -> folly::coro::Task<void> {
auto token = auto innerToken =
co_await folly::coro::co_current_cancellation_token; co_await folly::coro::co_current_cancellation_token;
co_await baton; co_await baton;
EXPECT_TRUE(token.isCancellationRequested()); EXPECT_TRUE(innerToken.isCancellationRequested());
})) }))
.scheduleOn(ex)); .scheduleOn(ex));
}); });
...@@ -2328,8 +2328,8 @@ TEST_F(CollectAnyRangeTest, OneTaskWithValue) { ...@@ -2328,8 +2328,8 @@ TEST_F(CollectAnyRangeTest, OneTaskWithValue) {
tasks.push_back(f()); tasks.push_back(f());
auto [index, result] = auto [index, result] =
co_await folly::coro::collectAnyRange(std::move(tasks)); co_await folly::coro::collectAnyRange(std::move(tasks));
CHECK_EQ("hello", result.value()); EXPECT_EQ("hello", result.value());
CHECK_EQ(0, index); EXPECT_EQ(0, index);
completed = true; completed = true;
}; };
...@@ -2339,19 +2339,19 @@ TEST_F(CollectAnyRangeTest, OneTaskWithValue) { ...@@ -2339,19 +2339,19 @@ TEST_F(CollectAnyRangeTest, OneTaskWithValue) {
executor.drain(); executor.drain();
CHECK(!completed); EXPECT_FALSE(completed);
baton.post(); baton.post();
// Posting the baton should have just scheduled the 'f()' coroutine // Posting the baton should have just scheduled the 'f()' coroutine
// for resumption on the executor but should not have executed // for resumption on the executor but should not have executed
// until we drain the executor again. // until we drain the executor again.
CHECK(!completed); EXPECT_FALSE(completed);
executor.drain(); executor.drain();
CHECK(completed); EXPECT_TRUE(completed);
CHECK(future.isReady()); EXPECT_TRUE(future.isReady());
} }
TEST_F(CollectAnyRangeTest, OneVoidTask) { TEST_F(CollectAnyRangeTest, OneVoidTask) {
...@@ -2370,7 +2370,7 @@ TEST_F(CollectAnyRangeTest, OneVoidTask) { ...@@ -2370,7 +2370,7 @@ TEST_F(CollectAnyRangeTest, OneVoidTask) {
co_await folly::coro::collectAnyRange(generateTasks()); co_await folly::coro::collectAnyRange(generateTasks());
(void)result; (void)result;
}()); }());
CHECK(completed); EXPECT_TRUE(completed);
} }
TEST_F(CollectAnyRangeTest, MoveOnlyType) { TEST_F(CollectAnyRangeTest, MoveOnlyType) {
...@@ -2389,7 +2389,7 @@ TEST_F(CollectAnyRangeTest, MoveOnlyType) { ...@@ -2389,7 +2389,7 @@ TEST_F(CollectAnyRangeTest, MoveOnlyType) {
co_await folly::coro::collectAnyRange(generateTasks()); co_await folly::coro::collectAnyRange(generateTasks());
(void)result; (void)result;
}()); }());
CHECK(completed); EXPECT_TRUE(completed);
} }
TEST_F(CollectAnyRangeTest, CollectAnyDoesntCompleteUntilAllTasksComplete) { TEST_F(CollectAnyRangeTest, CollectAnyDoesntCompleteUntilAllTasksComplete) {
...@@ -2418,29 +2418,29 @@ TEST_F(CollectAnyRangeTest, CollectAnyDoesntCompleteUntilAllTasksComplete) { ...@@ -2418,29 +2418,29 @@ TEST_F(CollectAnyRangeTest, CollectAnyDoesntCompleteUntilAllTasksComplete) {
auto [index, result] = auto [index, result] =
co_await folly::coro::collectAnyRange(generateTasks()); co_await folly::coro::collectAnyRange(generateTasks());
complete = true; complete = true;
CHECK_EQ(taskTerminatingExpectedIndex, index); EXPECT_EQ(taskTerminatingExpectedIndex, index);
CHECK_EQ(result.value(), 314); EXPECT_EQ(result.value(), 314);
}; };
folly::ManualExecutor executor; folly::ManualExecutor executor;
auto future = run().scheduleOn(&executor).start(); auto future = run().scheduleOn(&executor).start();
CHECK(!task1Started); EXPECT_FALSE(task1Started);
CHECK(!task2Started); EXPECT_FALSE(task2Started);
executor.drain(); executor.drain();
CHECK(task1Started); EXPECT_TRUE(task1Started);
CHECK(task2Started); EXPECT_TRUE(task2Started);
CHECK(!complete); EXPECT_FALSE(complete);
baton2.post(); baton2.post();
executor.drain(); executor.drain();
CHECK(!complete); EXPECT_FALSE(complete);
baton1.post(); baton1.post();
executor.drain(); executor.drain();
CHECK(complete); EXPECT_TRUE(complete);
CHECK(future.isReady()); EXPECT_TRUE(future.isReady());
} }
TEST_F(CollectAnyRangeTest, ThrowsFirstError) { TEST_F(CollectAnyRangeTest, ThrowsFirstError) {
...@@ -2480,15 +2480,15 @@ TEST_F(CollectAnyRangeTest, ThrowsFirstError) { ...@@ -2480,15 +2480,15 @@ TEST_F(CollectAnyRangeTest, ThrowsFirstError) {
// propagate out of collectAny(). // propagate out of collectAny().
auto [index, result] = auto [index, result] =
co_await folly::coro::collectAnyRange(generateTasks()); co_await folly::coro::collectAnyRange(generateTasks());
CHECK_EQ(1, index); EXPECT_EQ(1, index);
try { try {
result.value(); result.value();
CHECK(false); ADD_FAILURE() << "Hit unexpected codepath";
} catch (const ErrorB&) { } catch (const ErrorB&) {
caughtException = true; caughtException = true;
} }
}()); }());
CHECK(caughtException); EXPECT_TRUE(caughtException);
} }
TEST_F(CollectAnyRangeTest, CollectAnyCancelsSubtasksWhenASubtaskCompletes) { TEST_F(CollectAnyRangeTest, CollectAnyCancelsSubtasksWhenASubtaskCompletes) {
...@@ -2512,15 +2512,15 @@ TEST_F(CollectAnyRangeTest, CollectAnyCancelsSubtasksWhenASubtaskCompletes) { ...@@ -2512,15 +2512,15 @@ TEST_F(CollectAnyRangeTest, CollectAnyCancelsSubtasksWhenASubtaskCompletes) {
auto [index, result] = auto [index, result] =
co_await folly::coro::collectAnyRange(std::move(tasks)); co_await folly::coro::collectAnyRange(std::move(tasks));
CHECK_EQ(2, index); EXPECT_EQ(2, index);
try { try {
result.value(); result.value();
CHECK(false); ADD_FAILURE() << "Hit unexpected codepath";
} catch (const ErrorA&) { } catch (const ErrorA&) {
} }
auto end = std::chrono::steady_clock::now(); auto end = std::chrono::steady_clock::now();
CHECK((end - start) < 1s); EXPECT_LT(end - start, 1s);
}()); }());
} }
...@@ -2553,10 +2553,10 @@ TEST_F(CollectAnyRangeTest, CollectAnyCancelsSubtasksWhenParentTaskCancelled) { ...@@ -2553,10 +2553,10 @@ TEST_F(CollectAnyRangeTest, CollectAnyCancelsSubtasksWhenParentTaskCancelled) {
auto [index, result] = co_await folly::coro::co_withCancellation( auto [index, result] = co_await folly::coro::co_withCancellation(
cancelSource.getToken(), cancelSource.getToken(),
folly::coro::collectAnyRange(generateTasks())); folly::coro::collectAnyRange(generateTasks()));
CHECK(false); ADD_FAILURE() << "Hit unexpected codepath";
} catch (const folly::OperationCancelled&) { } catch (const folly::OperationCancelled&) {
auto end = std::chrono::steady_clock::now(); auto end = std::chrono::steady_clock::now();
CHECK((end - start) < 1s); EXPECT_LT(end - start, 1s);
} }
}()); }());
} }
...@@ -2572,10 +2572,10 @@ TEST_F(CollectAnyRangeTest, CancellationTokenRemainsActiveAfterReturn) { ...@@ -2572,10 +2572,10 @@ TEST_F(CollectAnyRangeTest, CancellationTokenRemainsActiveAfterReturn) {
scope.add( scope.add(
folly::coro::co_withCancellation( folly::coro::co_withCancellation(
token, folly::coro::co_invoke([&]() -> folly::coro::Task<void> { token, folly::coro::co_invoke([&]() -> folly::coro::Task<void> {
auto token = auto innerToken =
co_await folly::coro::co_current_cancellation_token; co_await folly::coro::co_current_cancellation_token;
co_await baton; co_await baton;
EXPECT_TRUE(token.isCancellationRequested()); EXPECT_TRUE(innerToken.isCancellationRequested());
})) }))
.scheduleOn(ex)); .scheduleOn(ex));
}); });
...@@ -2607,17 +2607,17 @@ TEST_F(CollectAnyNoDiscardRangeTest, OneTask) { ...@@ -2607,17 +2607,17 @@ TEST_F(CollectAnyNoDiscardRangeTest, OneTask) {
tasks.push_back(value()); tasks.push_back(value());
auto result = auto result =
co_await folly::coro::collectAnyNoDiscardRange(std::move(tasks)); co_await folly::coro::collectAnyNoDiscardRange(std::move(tasks));
CHECK_EQ(result.size(), 1); EXPECT_EQ(result.size(), 1);
CHECK(result[0].hasValue()); EXPECT_TRUE(result[0].hasValue());
CHECK_EQ("hello", result[0].value()); EXPECT_EQ("hello", result[0].value());
} }
{ {
std::vector<folly::coro::Task<std::string>> tasks; std::vector<folly::coro::Task<std::string>> tasks;
tasks.push_back(throws()); tasks.push_back(throws());
auto result = auto result =
co_await folly::coro::collectAnyNoDiscardRange(std::move(tasks)); co_await folly::coro::collectAnyNoDiscardRange(std::move(tasks));
CHECK_EQ(result.size(), 1); EXPECT_EQ(result.size(), 1);
CHECK(result[0].hasException<ErrorA>()); EXPECT_TRUE(result[0].hasException<ErrorA>());
} }
}()); }());
} }
...@@ -2643,10 +2643,10 @@ TEST_F(CollectAnyNoDiscardRangeTest, MultipleTasksWithValues) { ...@@ -2643,10 +2643,10 @@ TEST_F(CollectAnyNoDiscardRangeTest, MultipleTasksWithValues) {
tasks.push_back(busyWait(count, 3)); tasks.push_back(busyWait(count, 3));
auto result = auto result =
co_await folly::coro::collectAnyNoDiscardRange(std::move(tasks)); co_await folly::coro::collectAnyNoDiscardRange(std::move(tasks));
CHECK_EQ(result.size(), 3); EXPECT_EQ(result.size(), 3);
CHECK(result[0].hasValue()); EXPECT_TRUE(result[0].hasValue());
CHECK(result[1].hasValue()); EXPECT_TRUE(result[1].hasValue());
CHECK(result[2].hasValue()); EXPECT_TRUE(result[2].hasValue());
}()); }());
} }
...@@ -2665,7 +2665,7 @@ TEST_F(CollectAnyNoDiscardRangeTest, OneVoidTask) { ...@@ -2665,7 +2665,7 @@ TEST_F(CollectAnyNoDiscardRangeTest, OneVoidTask) {
co_await folly::coro::collectAnyNoDiscardRange(std::move(tasks)); co_await folly::coro::collectAnyNoDiscardRange(std::move(tasks));
EXPECT_EQ(result.size(), 1); EXPECT_EQ(result.size(), 1);
}()); }());
CHECK(completed); EXPECT_TRUE(completed);
} }
TEST_F(CollectAnyNoDiscardRangeTest, DoesntCompleteUntilAllTasksComplete) { TEST_F(CollectAnyNoDiscardRangeTest, DoesntCompleteUntilAllTasksComplete) {
...@@ -2693,32 +2693,32 @@ TEST_F(CollectAnyNoDiscardRangeTest, DoesntCompleteUntilAllTasksComplete) { ...@@ -2693,32 +2693,32 @@ TEST_F(CollectAnyNoDiscardRangeTest, DoesntCompleteUntilAllTasksComplete) {
auto result = auto result =
co_await folly::coro::collectAnyNoDiscardRange(generateTasks()); co_await folly::coro::collectAnyNoDiscardRange(generateTasks());
complete = true; complete = true;
CHECK_EQ(result.size(), 2); EXPECT_EQ(result.size(), 2);
CHECK(result[0].hasValue()); EXPECT_TRUE(result[0].hasValue());
CHECK_EQ(result[0].value(), 42); EXPECT_EQ(result[0].value(), 42);
CHECK(result[1].hasValue()); EXPECT_TRUE(result[1].hasValue());
CHECK_EQ(result[1].value(), 314); EXPECT_EQ(result[1].value(), 314);
}; };
folly::ManualExecutor executor; folly::ManualExecutor executor;
auto future = run().scheduleOn(&executor).start(); auto future = run().scheduleOn(&executor).start();
CHECK(!task1Started); EXPECT_FALSE(task1Started);
CHECK(!task2Started); EXPECT_FALSE(task2Started);
executor.drain(); executor.drain();
CHECK(task1Started); EXPECT_TRUE(task1Started);
CHECK(task2Started); EXPECT_TRUE(task2Started);
CHECK(!complete); EXPECT_FALSE(complete);
baton2.post(); baton2.post();
executor.drain(); executor.drain();
CHECK(!complete); EXPECT_FALSE(complete);
baton1.post(); baton1.post();
executor.drain(); executor.drain();
CHECK(complete); EXPECT_TRUE(complete);
CHECK(future.isReady()); EXPECT_TRUE(future.isReady());
} }
TEST_F(CollectAnyNoDiscardRangeTest, ThrowsAllErrors) { TEST_F(CollectAnyNoDiscardRangeTest, ThrowsAllErrors) {
...@@ -2745,10 +2745,10 @@ TEST_F(CollectAnyNoDiscardRangeTest, ThrowsAllErrors) { ...@@ -2745,10 +2745,10 @@ TEST_F(CollectAnyNoDiscardRangeTest, ThrowsAllErrors) {
}; };
auto result = auto result =
co_await folly::coro::collectAnyNoDiscardRange(generateTasks()); co_await folly::coro::collectAnyNoDiscardRange(generateTasks());
CHECK_EQ(result.size(), 3); EXPECT_EQ(result.size(), 3);
CHECK(result[0].hasException<ErrorA>()); EXPECT_TRUE(result[0].hasException<ErrorA>());
CHECK(result[1].hasException<ErrorB>()); EXPECT_TRUE(result[1].hasException<ErrorB>());
CHECK(result[2].hasException<ErrorC>()); EXPECT_TRUE(result[2].hasException<ErrorC>());
}()); }());
} }
...@@ -2775,14 +2775,14 @@ TEST_F(CollectAnyNoDiscardRangeTest, CancelSubtasksWhenASubtaskCompletes) { ...@@ -2775,14 +2775,14 @@ TEST_F(CollectAnyNoDiscardRangeTest, CancelSubtasksWhenASubtaskCompletes) {
}; };
auto result = auto result =
co_await folly::coro::collectAnyNoDiscardRange(generateTasks()); co_await folly::coro::collectAnyNoDiscardRange(generateTasks());
CHECK_EQ(result.size(), 3); EXPECT_EQ(result.size(), 3);
CHECK(result[0].hasException<folly::OperationCancelled>()); EXPECT_TRUE(result[0].hasException<folly::OperationCancelled>());
CHECK(result[1].hasException<folly::OperationCancelled>()); EXPECT_TRUE(result[1].hasException<folly::OperationCancelled>());
CHECK(result[2].hasException<ErrorA>()); EXPECT_TRUE(result[2].hasException<ErrorA>());
auto end = std::chrono::steady_clock::now(); auto end = std::chrono::steady_clock::now();
CHECK((end - start) < 1s); EXPECT_LT(end - start, 1s);
}()); }());
} }
...@@ -2816,11 +2816,11 @@ TEST_F(CollectAnyNoDiscardRangeTest, CancelSubtasksWhenParentTaskCancelled) { ...@@ -2816,11 +2816,11 @@ TEST_F(CollectAnyNoDiscardRangeTest, CancelSubtasksWhenParentTaskCancelled) {
cancelSource.getToken(), cancelSource.getToken(),
folly::coro::collectAnyNoDiscardRange(generateTasks())); folly::coro::collectAnyNoDiscardRange(generateTasks()));
auto end = std::chrono::steady_clock::now(); auto end = std::chrono::steady_clock::now();
CHECK((end - start) < 1s); EXPECT_LT(end - start, 1s);
CHECK_EQ(result.size(), 3); EXPECT_EQ(result.size(), 3);
CHECK(result[0].hasException<folly::OperationCancelled>()); EXPECT_TRUE(result[0].hasException<folly::OperationCancelled>());
CHECK(result[1].hasException<folly::OperationCancelled>()); EXPECT_TRUE(result[1].hasException<folly::OperationCancelled>());
CHECK(result[2].hasException<folly::OperationCancelled>()); EXPECT_TRUE(result[2].hasException<folly::OperationCancelled>());
}()); }());
} }
...@@ -2837,10 +2837,10 @@ TEST_F( ...@@ -2837,10 +2837,10 @@ TEST_F(
scope.add( scope.add(
folly::coro::co_withCancellation( folly::coro::co_withCancellation(
token, folly::coro::co_invoke([&]() -> folly::coro::Task<void> { token, folly::coro::co_invoke([&]() -> folly::coro::Task<void> {
auto token = auto innerToken =
co_await folly::coro::co_current_cancellation_token; co_await folly::coro::co_current_cancellation_token;
co_await baton; co_await baton;
EXPECT_TRUE(token.isCancellationRequested()); EXPECT_TRUE(innerToken.isCancellationRequested());
})) }))
.scheduleOn(ex)); .scheduleOn(ex));
})); }));
......
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