Skip to content

Commit 44ad32a

Browse files
authored
Merge pull request ceph#62649 from Matan-B/wip-matanb-crimson-coroutines-errors
test/crimson/test_crimson_coroutines: showcase errorator examples Reviewed-by: Samuel Just <[email protected]> Reviewed-by: Yingxin Cheng <[email protected]>
2 parents 9cb8feb + 34b7ca1 commit 44ad32a

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/test/crimson/test_crimson_coroutine.cc

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,58 @@ TEST_F(coroutine_test_t, test_ertr_coroutine_error)
163163
});
164164
}
165165

166+
// same as test_ertr_coroutine_error but without ignoring the
167+
// exeptional future.
168+
TEST_F(coroutine_test_t, test_ertr_coroutine_error_2)
169+
{
170+
run_scl([this]() -> seastar::future<> {
171+
172+
auto fut = scl([]() -> ertr::future<int> {
173+
co_await ertr::future<int>(crimson::ct_error::invarg::make());
174+
EXPECT_EQ("above co_await should throw", nullptr);
175+
co_return 10;
176+
})();
177+
178+
auto ret = co_await std::move(fut).handle_error(
179+
[](const crimson::ct_error::invarg &e) {
180+
return 20;
181+
}
182+
);
183+
EXPECT_EQ(ret, 20);
184+
});
185+
}
186+
187+
TEST_F(coroutine_test_t, test_ertr_coroutine_pass_further)
188+
{
189+
run_scl([this]() -> seastar::future<> {
190+
191+
// foo1 makes an error which throws
192+
auto fut = scl([]() -> ertr::future<int> {
193+
co_await ertr::future<int>(crimson::ct_error::invarg::make());
194+
EXPECT_EQ("above co_await should throw", nullptr);
195+
co_return 10;
196+
})();
197+
198+
// foo2 handles the error and passes it further
199+
auto fut2 = scl([fut = std::move(fut)]() mutable -> ertr::future<int> {
200+
co_await std::move(fut).handle_error(
201+
ertr::pass_further{}
202+
);
203+
EXPECT_EQ("above co_await should throw", nullptr);
204+
co_return 10;
205+
})();
206+
207+
// handle the passed further error from foo2
208+
auto ret = co_await std::move(fut2).handle_error(
209+
[](const crimson::ct_error::invarg &e) {
210+
return 20;
211+
}
212+
);
213+
214+
EXPECT_EQ(ret, 20);
215+
});
216+
}
217+
166218
#if 0
167219
// This one is left in, but commented out, as a test which *should fail to
168220
// build* due to trying to co_await a more errorated future.

0 commit comments

Comments
 (0)