Merge branch 'pratik/std-coro/migrate-test-code' into pratik/std-coro/cleanup-boost-coroutine

This commit is contained in:
Pratik Mankawde
2026-07-27 13:06:43 +01:00
2 changed files with 30 additions and 20 deletions

View File

@@ -70,11 +70,13 @@ public:
Gate g1, g2;
std::shared_ptr<JobQueue::CoroTaskRunner> c;
// Safe capture: the test blocks on the Gates until the coroutine
// completes, so the captured pointers outlive the coroutine.
// NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines)
env.app().getJobQueue().postCoroTask(
JtClient, "CoroTest", [cp = &c, g1p = &g1, g2p = &g2](auto runner) -> CoroTask<void> {
JtClient,
"CoroTest",
// Safe capture: the test blocks on the Gates until the coroutine
// completes, so the captured pointers outlive the coroutine.
// NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines)
[cp = &c, g1p = &g1, g2p = &g2](auto runner) -> CoroTask<void> {
*cp = runner;
g1p->signal();
co_await runner->suspend();
@@ -102,11 +104,13 @@ public:
}));
Gate g;
// Safe capture: the test blocks on the Gate until the coroutine
// completes, so the captured pointer outlives the coroutine.
// NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines)
env.app().getJobQueue().postCoroTask(
JtClient, "CoroTest", [gp = &g](auto runner) -> CoroTask<void> {
JtClient,
"CoroTest",
// Safe capture: the test blocks on the Gate until the coroutine
// completes, so the captured pointer outlives the coroutine.
// NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines)
[gp = &g](auto runner) -> CoroTask<void> {
// Schedule a resume before suspending. The posted job
// cannot actually call resume() until the current resume()
// releases CoroTaskRunner::mutex_, which only happens after

View File

@@ -60,11 +60,13 @@ class JobQueue_test : public beast::unit_test::Suite
{
// Test repeated post()s until the coroutine completes.
std::atomic<int> yieldCount{0};
// Safe capture: the test blocks below until the coroutine
// completes, so the captured pointer outlives the coroutine.
// NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines)
auto const runner = jQueue.postCoroTask(
JtClient, "PostCoroTest1", [ycp = &yieldCount](auto runner) -> CoroTask<void> {
JtClient,
"PostCoroTest1",
// Safe capture: the test blocks below until the coroutine
// completes, so the captured pointer outlives the coroutine.
// NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines)
[ycp = &yieldCount](auto runner) -> CoroTask<void> {
while (++(*ycp) < 4)
co_await runner->suspend();
co_return;
@@ -91,11 +93,13 @@ class JobQueue_test : public beast::unit_test::Suite
{
// Test repeated post()+join()s until the coroutine completes.
int yieldCount{0};
// Safe capture: the test blocks below until the coroutine
// completes, so the captured pointer outlives the coroutine.
// NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines)
auto const runner = jQueue.postCoroTask(
JtClient, "PostCoroTest2", [ycp = &yieldCount](auto runner) -> CoroTask<void> {
JtClient,
"PostCoroTest2",
// Safe capture: the test blocks below until the coroutine
// completes, so the captured pointer outlives the coroutine.
// NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines)
[ycp = &yieldCount](auto runner) -> CoroTask<void> {
while (++(*ycp) < 4)
co_await runner->suspend();
co_return;
@@ -138,11 +142,13 @@ class JobQueue_test : public beast::unit_test::Suite
// unprotected variable on the stack should be completely safe.
// Not recommended for the faint of heart...
bool unprotected = false;
// Safe capture: the JobQueue is stopped, so the coroutine is
// never started and the captured pointer is never dereferenced.
// NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines)
auto const runner = jQueue.postCoroTask(
JtClient, "PostCoroTest3", [up = &unprotected](auto) -> CoroTask<void> {
JtClient,
"PostCoroTest3",
// Safe capture: the JobQueue is stopped, so the coroutine is
// never started and the captured pointer is never dereferenced.
// NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines)
[up = &unprotected](auto) -> CoroTask<void> {
*up = true;
co_return;
});