Commit 59277b68 authored by Lewis Baker's avatar Lewis Baker Committed by Facebook GitHub Bot

Fix some dangling reference bugs in folly::coro::Task tests

Summary:
The TaskTests::FutureRoundtrip and TaskTests::StartInlineUnsafe tests were
incorrectly using stateful lambdas in a way that leads to the coroutines
having a dangling reference to a destructed temporary lambda. This was causing
ASAN failures.

This changes those usages to instead use stateless lambdas.

Reviewed By: lxfind

Differential Revision: D24542508

fbshipit-source-id: 034d397b79e0553094a14d2cb6d00fe3816b4b92
parent f9a8116a
...@@ -346,23 +346,20 @@ TEST_F(TaskTest, FutureTailCall) { ...@@ -346,23 +346,20 @@ TEST_F(TaskTest, FutureTailCall) {
} }
TEST_F(TaskTest, FutureRoundtrip) { TEST_F(TaskTest, FutureRoundtrip) {
auto task = []() -> folly::coro::Task<void> { co_return; }(); folly::coro::blockingWait([]() -> folly::coro::Task<void> {
auto semi = std::move(task).semi(); co_yield folly::coro::co_result(co_await folly::coro::co_awaitTry(
task = [&]() -> folly::coro::Task<void> { []() -> folly::coro::Task<void> { co_return; }().semi()));
co_yield folly::coro::co_result( }());
co_await folly::coro::co_awaitTry(std::move(semi)));
}();
folly::coro::blockingWait(std::move(task));
task = []() -> folly::coro::Task<void> { EXPECT_THROW(
folly::coro::blockingWait([]() -> folly::coro::Task<void> {
co_yield folly::coro::co_result(co_await folly::coro::co_awaitTry(
[]() -> folly::coro::Task<void> {
co_yield folly::coro::co_error(std::runtime_error("")); co_yield folly::coro::co_error(std::runtime_error(""));
}(); }()
semi = std::move(task).semi(); .semi()));
task = [&]() -> folly::coro::Task<void> { }()),
co_yield folly::coro::co_result( std::runtime_error);
co_await folly::coro::co_awaitTry(std::move(semi)));
}();
EXPECT_THROW(folly::coro::blockingWait(std::move(task)), std::runtime_error);
} }
// NOTE: This function is unused. // NOTE: This function is unused.
...@@ -444,13 +441,12 @@ TEST_F(TaskTest, StartInlineUnsafe) { ...@@ -444,13 +441,12 @@ TEST_F(TaskTest, StartInlineUnsafe) {
auto executor = co_await folly::coro::co_current_executor; auto executor = co_await folly::coro::co_current_executor;
bool hasStarted = false; bool hasStarted = false;
bool hasFinished = false; bool hasFinished = false;
auto sf = [&]() -> folly::coro::Task<void> { auto makeTask = [&]() -> folly::coro::Task<void> {
hasStarted = true; hasStarted = true;
co_await folly::coro::co_reschedule_on_current_executor; co_await folly::coro::co_reschedule_on_current_executor;
hasFinished = true; hasFinished = true;
}() };
.scheduleOn(executor) auto sf = makeTask().scheduleOn(executor).startInlineUnsafe();
.startInlineUnsafe();
// Check that the task started inline on the current thread. // Check that the task started inline on the current thread.
// It should not yet have completed, however, since the rest // It should not yet have completed, however, since the rest
......
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