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 12:36:46 +01:00
4 changed files with 37 additions and 1 deletions

View File

@@ -187,6 +187,9 @@ public:
json::Value result;
Gate g;
// Safe capture: the test blocks on g.waitFor() until the coroutine
// completes, so the captured locals outlive the coroutine.
// NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines)
app.getJobQueue().postCoroTask(JtClient, "RPC-Client", [&](auto) -> CoroTask<void> {
context.params = std::move(params);
RPC::doCommand(context, result);
@@ -280,6 +283,9 @@ public:
json::Value result;
Gate g;
// Test RPC::Tuning::max_src_cur source currencies.
// Safe capture: the test blocks on g.waitFor() until the coroutine
// completes, so the captured locals outlive the coroutine.
// NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines)
app.getJobQueue().postCoroTask(JtClient, "RPC-Client", [&](auto) -> CoroTask<void> {
context.params = rpf(Account("alice"), Account("bob"), RPC::Tuning::kMaxSrcCur);
RPC::doCommand(context, result);
@@ -290,6 +296,9 @@ public:
BEAST_EXPECT(!result.isMember(jss::error));
// Test more than RPC::Tuning::max_src_cur source currencies.
// Safe capture: the test blocks on g.waitFor() until the coroutine
// completes, so the captured locals outlive the coroutine.
// NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines)
app.getJobQueue().postCoroTask(JtClient, "RPC-Client", [&](auto) -> CoroTask<void> {
context.params = rpf(Account("alice"), Account("bob"), RPC::Tuning::kMaxSrcCur + 1);
RPC::doCommand(context, result);
@@ -302,6 +311,9 @@ public:
// Test RPC::Tuning::max_auto_src_cur source currencies.
for (auto i = 0; i < (RPC::Tuning::kMaxAutoSrcCur - 1); ++i)
env.trust(Account("alice")[std::to_string(i + 100)](100), "bob");
// Safe capture: the test blocks on g.waitFor() until the coroutine
// completes, so the captured locals outlive the coroutine.
// NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines)
app.getJobQueue().postCoroTask(JtClient, "RPC-Client", [&](auto) -> CoroTask<void> {
context.params = rpf(Account("alice"), Account("bob"), 0);
RPC::doCommand(context, result);
@@ -313,6 +325,9 @@ public:
// Test more than RPC::Tuning::max_auto_src_cur source currencies.
env.trust(Account("alice")["AUD"](100), "bob");
// Safe capture: the test blocks on g.waitFor() until the coroutine
// completes, so the captured locals outlive the coroutine.
// NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines)
app.getJobQueue().postCoroTask(JtClient, "RPC-Client", [&](auto) -> CoroTask<void> {
context.params = rpf(Account("alice"), Account("bob"), 0);
RPC::doCommand(context, result);

View File

@@ -70,6 +70,9 @@ 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> {
*cp = runner;
@@ -99,6 +102,9 @@ 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> {
// Schedule a resume before suspending. The posted job
@@ -145,6 +151,10 @@ public:
jq.postCoroTask(
JtClient,
"CoroTest",
// Safe capture: the test drives every coroutine to completion
// via the Gate/post()/join() sequences below, so the captured
// pointers outlive the coroutines.
// NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines)
[this, ap = &a, gp = &g, lvp = &lv, id = i](auto runner) -> CoroTask<void> {
(*ap)[id] = runner;
gp->signal();

View File

@@ -6,7 +6,6 @@
#include <xrpl/core/JobQueue.h>
#include <atomic>
#include <memory>
namespace xrpl::test {
@@ -61,6 +60,9 @@ 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> {
while (++(*ycp) < 4)
@@ -89,6 +91,9 @@ 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> {
while (++(*ycp) < 4)
@@ -133,6 +138,9 @@ 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> {
*up = true;

View File

@@ -250,6 +250,9 @@ findPathsRequest(
json::Value result;
Gate g;
// Safe capture: the caller blocks on g.waitFor() until the coroutine
// completes, so the captured locals outlive the coroutine.
// NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines)
app.getJobQueue().postCoroTask(JtClient, "RPC-Client", [&](auto) -> CoroTask<void> {
context.params = std::move(params);
RPC::doCommand(context, result);