]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test/crimson/test_errorator: showcase assert_all/handle/pass_furhter 62635/head
authorMatan Breizman <mbreizma@redhat.com>
Mon, 7 Apr 2025 09:44:14 +0000 (09:44 +0000)
committerMatan Breizman <mbreizma@redhat.com>
Mon, 7 Apr 2025 09:44:14 +0000 (09:44 +0000)
Signed-off-by: Matan Breizman <mbreizma@redhat.com>
src/test/crimson/test_errorator.cc

index a7ee0cb35917013cde397c67a3a98cff4854220a..86eb478be29d7af1bde030474c1afcec87a3ca6c 100644 (file)
 struct errorator_test_t : public seastar_test_suite_t {
   using ertr = crimson::errorator<crimson::ct_error::invarg>;
 
+  ertr::future<> invarg_foo() {
+    return crimson::ct_error::invarg::make();
+  };
+
+  ertr::future<> clean_foo() {
+    return ertr::now();
+  };
+
   struct noncopyable_t {
     constexpr noncopyable_t() = default;
     ~noncopyable_t() = default;
@@ -85,3 +93,43 @@ TEST_F(errorator_test_t, test_futurization)
     }).unsafe_get();
   });
 }
+
+TEST_F(errorator_test_t, no_handle_error)
+{
+  run_async([this] {
+    return clean_foo().handle_error(
+      crimson::ct_error::assert_all("unexpected error")
+    ).get();
+  });
+}
+
+TEST_F(errorator_test_t, handle_specific_error)
+{
+  int res = 0;
+  run_async([&res, this] {
+  return invarg_foo().handle_error(
+    crimson::ct_error::invarg::handle([&res] (const auto& ec) {
+      EXPECT_EQ(ec.value(), EINVAL);
+      res = 1;
+      return seastar::now();
+    }),
+    crimson::ct_error::assert_all("unexpected error")).get();
+  });
+  EXPECT_EQ(res, 1);
+}
+
+TEST_F(errorator_test_t, pass_further_error)
+{
+  int res = 0;
+  run_async([&res, this] {
+    return invarg_foo().handle_error(
+      ertr::pass_further{}
+    ).handle_error(
+      crimson::ct_error::invarg::handle([&res] (const auto& ec) {
+      res = 1;
+      return seastar::now();
+    }),
+    crimson::ct_error::assert_all("unexpected error")).get();
+  });
+  EXPECT_EQ(res, 1);
+}