From: Matan Breizman Date: Thu, 3 Apr 2025 09:02:05 +0000 (+0000) Subject: test/crimson/test_crimson_coroutines: showcase errorator examples X-Git-Tag: testing/wip-vshankar-testing-20250407.170244-debug~5^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=34b7ca105647869d948f00eea025c1ec8e4d3666;p=ceph-ci.git test/crimson/test_crimson_coroutines: showcase errorator examples This came up in https://github.com/ceph/ceph/pull/62530. Showcase an awaited throwing coroutine and a passed_further error. Signed-off-by: Matan Breizman --- diff --git a/src/test/crimson/test_crimson_coroutine.cc b/src/test/crimson/test_crimson_coroutine.cc index 86743b374dc..e123f63d97e 100644 --- a/src/test/crimson/test_crimson_coroutine.cc +++ b/src/test/crimson/test_crimson_coroutine.cc @@ -163,6 +163,58 @@ TEST_F(coroutine_test_t, test_ertr_coroutine_error) }); } +// same as test_ertr_coroutine_error but without ignoring the +// exeptional future. +TEST_F(coroutine_test_t, test_ertr_coroutine_error_2) +{ + run_scl([this]() -> seastar::future<> { + + auto fut = scl([]() -> ertr::future { + co_await ertr::future(crimson::ct_error::invarg::make()); + EXPECT_EQ("above co_await should throw", nullptr); + co_return 10; + })(); + + auto ret = co_await std::move(fut).handle_error( + [](const crimson::ct_error::invarg &e) { + return 20; + } + ); + EXPECT_EQ(ret, 20); + }); +} + +TEST_F(coroutine_test_t, test_ertr_coroutine_pass_further) +{ + run_scl([this]() -> seastar::future<> { + + // foo1 makes an error which throws + auto fut = scl([]() -> ertr::future { + co_await ertr::future(crimson::ct_error::invarg::make()); + EXPECT_EQ("above co_await should throw", nullptr); + co_return 10; + })(); + + // foo2 handles the error and passes it further + auto fut2 = scl([fut = std::move(fut)]() mutable -> ertr::future { + co_await std::move(fut).handle_error( + ertr::pass_further{} + ); + EXPECT_EQ("above co_await should throw", nullptr); + co_return 10; + })(); + + // handle the passed further error from foo2 + auto ret = co_await std::move(fut2).handle_error( + [](const crimson::ct_error::invarg &e) { + return 20; + } + ); + + EXPECT_EQ(ret, 20); + }); +} + #if 0 // This one is left in, but commented out, as a test which *should fail to // build* due to trying to co_await a more errorated future.