From: Matan Breizman Date: Mon, 7 Apr 2025 09:44:14 +0000 (+0000) Subject: test/crimson/test_errorator: showcase assert_all/handle/pass_furhter X-Git-Tag: v20.3.0~149^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F62635%2Fhead;p=ceph.git test/crimson/test_errorator: showcase assert_all/handle/pass_furhter Signed-off-by: Matan Breizman --- diff --git a/src/test/crimson/test_errorator.cc b/src/test/crimson/test_errorator.cc index a7ee0cb35917..86eb478be29d 100644 --- a/src/test/crimson/test_errorator.cc +++ b/src/test/crimson/test_errorator.cc @@ -14,6 +14,14 @@ struct errorator_test_t : public seastar_test_suite_t { using ertr = crimson::errorator; + 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); +}