From a02f6b037109bfda14d1e644f5dadc5a5f59c278 Mon Sep 17 00:00:00 2001 From: Matan Breizman Date: Mon, 15 Dec 2025 12:39:49 +0000 Subject: [PATCH] test/crimson/test_crimson_coroutine: introduce repeat example interruptible repeat methods use internally seastar::repeat which require passing a seastar::stop_iteration. Using coroutines, it's far nicer to use primitive for/while loops with interrutible futures inside. Adding interruptible_coroutine_interrupted_repeat as an example. to a discussion from https://github.com/ceph/ceph/pull/65157 Signed-off-by: Matan Breizman --- src/test/crimson/test_crimson_coroutine.cc | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/test/crimson/test_crimson_coroutine.cc b/src/test/crimson/test_crimson_coroutine.cc index 43733b11e1f..86e07406a16 100644 --- a/src/test/crimson/test_crimson_coroutine.cc +++ b/src/test/crimson/test_crimson_coroutine.cc @@ -14,6 +14,8 @@ #include "test/crimson/gtest_seastar.h" +using namespace std::chrono_literals; + struct coroutine_test_t : public seastar_test_suite_t { struct interruption_state_t { bool interrupted = false; @@ -262,6 +264,27 @@ TEST_F(coroutine_test_t, interruptible_coroutine_interrupted) }); } +TEST_F(coroutine_test_t, interruptible_coroutine_interrupted_repeat) +{ + run_scl([this]() -> seastar::future<> { + int count = 0; + auto ret = cwi( + [](auto) { return 2; }, + [&count]() mutable -> interruptor::future { + while (true) { + count++; + co_await interruptor::make_interruptible(seastar::sleep(100ms)); + continue; + } + }); + auto backgroud = seastar::sleep(3s).then([this]{interrupt();}); + auto awaited = co_await std::move(ret); + EXPECT_EQ(awaited, 2); + // Make sure that there were a few iterations prior to interrupting.. + EXPECT_GE(count, 10); + }); +} + TEST_F(coroutine_test_t, dual_interruptible_coroutine) { run_scl([this]() -> seastar::future<> { -- 2.47.3