]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test/crimson/test_crimson_coroutines: showcase errorator examples 62649/head
authorMatan Breizman <mbreizma@redhat.com>
Thu, 3 Apr 2025 09:02:05 +0000 (09:02 +0000)
committerMatan Breizman <mbreizma@redhat.com>
Thu, 3 Apr 2025 11:33:55 +0000 (11:33 +0000)
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 <mbreizma@redhat.com>
src/test/crimson/test_crimson_coroutine.cc

index 86743b374dcdced8bcd18fa589d5072bb1b925e1..e123f63d97efbbf7539ecf8a805c222bf298e025 100644 (file)
@@ -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<int> {
+      co_await ertr::future<int>(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<int> {
+      co_await ertr::future<int>(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<int> {
+      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.