diff --git a/utils/error_injection.hh b/utils/error_injection.hh index f64cf2dc46..ab39019b80 100644 --- a/utils/error_injection.hh +++ b/utils/error_injection.hh @@ -363,27 +363,19 @@ public: // \param f lambda to be run [[gnu::always_inline]] void inject(const std::string_view& name, handler_fun f) { - if (!is_enabled(name)) { + if (!enter(name)) { return; } - if (is_one_shot(name)) { - disable(name); - } errinj_logger.debug("Triggering injection \"{}\"", name); f(); } // \brief Inject a sleep for milliseconds [[gnu::always_inline]] - future<> inject(const std::string_view& name, - const std::chrono::milliseconds duration) { - - if (!is_enabled(name)) { + future<> inject(const std::string_view& name, const std::chrono::milliseconds duration) { + if (!enter(name)) { return make_ready_future<>(); } - if (is_one_shot(name)) { - disable(name); - } errinj_logger.debug("Triggering sleep injection \"{}\" ({}ms)", name, duration.count()); return seastar::sleep(duration); } @@ -392,13 +384,9 @@ public: template [[gnu::always_inline]] future<> inject(const std::string_view& name, std::chrono::time_point deadline) { - - if (!is_enabled(name)) { + if (!enter(name)) { return make_ready_future<>(); } - if (is_one_shot(name)) { - disable(name); - } // Time left until deadline auto duration = deadline - Clock::now(); @@ -412,10 +400,7 @@ public: [[gnu::always_inline]] std::invoke_result_t inject(const std::string_view& name, std::chrono::time_point deadline, Func&& func) { - if (is_enabled(name)) { - if (is_one_shot(name)) { - disable(name); - } + if (enter(name)) { std::chrono::milliseconds duration = std::chrono::duration_cast(deadline - Clock::now()); errinj_logger.debug("Triggering sleep injection \"{}\" ({}ms)", name, duration.count()); return seastar::sleep(duration).then([func = std::move(func)] { @@ -431,15 +416,11 @@ public: requires std::is_invocable_r_v [[gnu::always_inline]] future<> - inject(const std::string_view& name, - Func&& exception_factory) { - - if (!is_enabled(name)) { + inject(const std::string_view& name, Func&& exception_factory) { + if (!enter(name)) { return make_ready_future<>(); } - if (is_one_shot(name)) { - disable(name); - } + errinj_logger.debug("Triggering exception injection \"{}\"", name); return make_exception_future<>(exception_factory()); }