diff --git a/test/boost/error_injection_test.cc b/test/boost/error_injection_test.cc index fe0c6db4d6..8dfa59244c 100644 --- a/test/boost/error_injection_test.cc +++ b/test/boost/error_injection_test.cc @@ -22,6 +22,7 @@ #include "test/lib/cql_test_env.hh" #include #include +#include #include "utils/error_injection.hh" #include "db/timeout_clock.hh" #include "test/lib/cql_assertions.hh" @@ -184,6 +185,27 @@ SEASTAR_TEST_CASE(test_error_exceptions) { return make_ready_future<>(); } +SEASTAR_TEST_CASE(test_is_timeout_exception) { + for (auto ep : { + std::make_exception_ptr(seastar::rpc::timeout_error()), + std::make_exception_ptr(seastar::semaphore_timed_out()), + std::make_exception_ptr(seastar::timed_out_error()), + }) + { + BOOST_TEST(is_timeout_exception(ep)); + try { + std::rethrow_exception(ep); + } catch (...) { + try { + std::throw_with_nested(std::runtime_error("Hello")); + } catch (...) { + BOOST_TEST(is_timeout_exception(std::current_exception())); + } + } + } + return make_ready_future<>(); +} + SEASTAR_TEST_CASE(test_inject_exception) { utils::error_injection errinj; diff --git a/utils/exceptions.cc b/utils/exceptions.cc index a5202cf12e..9b1537ea34 100644 --- a/utils/exceptions.cc +++ b/utils/exceptions.cc @@ -80,6 +80,8 @@ bool is_timeout_exception(std::exception_ptr e) { return true; } catch (seastar::timed_out_error& unused) { return true; + } catch (const std::nested_exception& e) { + return is_timeout_exception(e.nested_ptr()); } catch (...) { } return false;