|
14 | 14 | struct errorator_test_t : public seastar_test_suite_t { |
15 | 15 | using ertr = crimson::errorator<crimson::ct_error::invarg>; |
16 | 16 |
|
| 17 | + ertr::future<> invarg_foo() { |
| 18 | + return crimson::ct_error::invarg::make(); |
| 19 | + }; |
| 20 | + |
| 21 | + ertr::future<> clean_foo() { |
| 22 | + return ertr::now(); |
| 23 | + }; |
| 24 | + |
17 | 25 | struct noncopyable_t { |
18 | 26 | constexpr noncopyable_t() = default; |
19 | 27 | ~noncopyable_t() = default; |
@@ -85,3 +93,43 @@ TEST_F(errorator_test_t, test_futurization) |
85 | 93 | }).unsafe_get(); |
86 | 94 | }); |
87 | 95 | } |
| 96 | + |
| 97 | +TEST_F(errorator_test_t, no_handle_error) |
| 98 | +{ |
| 99 | + run_async([this] { |
| 100 | + return clean_foo().handle_error( |
| 101 | + crimson::ct_error::assert_all("unexpected error") |
| 102 | + ).get(); |
| 103 | + }); |
| 104 | +} |
| 105 | + |
| 106 | +TEST_F(errorator_test_t, handle_specific_error) |
| 107 | +{ |
| 108 | + int res = 0; |
| 109 | + run_async([&res, this] { |
| 110 | + return invarg_foo().handle_error( |
| 111 | + crimson::ct_error::invarg::handle([&res] (const auto& ec) { |
| 112 | + EXPECT_EQ(ec.value(), EINVAL); |
| 113 | + res = 1; |
| 114 | + return seastar::now(); |
| 115 | + }), |
| 116 | + crimson::ct_error::assert_all("unexpected error")).get(); |
| 117 | + }); |
| 118 | + EXPECT_EQ(res, 1); |
| 119 | +} |
| 120 | + |
| 121 | +TEST_F(errorator_test_t, pass_further_error) |
| 122 | +{ |
| 123 | + int res = 0; |
| 124 | + run_async([&res, this] { |
| 125 | + return invarg_foo().handle_error( |
| 126 | + ertr::pass_further{} |
| 127 | + ).handle_error( |
| 128 | + crimson::ct_error::invarg::handle([&res] (const auto& ec) { |
| 129 | + res = 1; |
| 130 | + return seastar::now(); |
| 131 | + }), |
| 132 | + crimson::ct_error::assert_all("unexpected error")).get(); |
| 133 | + }); |
| 134 | + EXPECT_EQ(res, 1); |
| 135 | +} |
0 commit comments