From c35533d675cbdd7428627cc277fc8b0009fa5c22 Mon Sep 17 00:00:00 2001 From: Ayanda Dube Date: Tue, 22 Jul 2025 16:26:51 +0100 Subject: [PATCH] introduce rabbit_ct_helpers:await_condition_* helpers which ignore exceptions --- .../src/rabbit_ct_helpers.erl | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/deps/rabbitmq_ct_helpers/src/rabbit_ct_helpers.erl b/deps/rabbitmq_ct_helpers/src/rabbit_ct_helpers.erl index 88d1f3ce85..b70e0a00c5 100644 --- a/deps/rabbitmq_ct_helpers/src/rabbit_ct_helpers.erl +++ b/deps/rabbitmq_ct_helpers/src/rabbit_ct_helpers.erl @@ -55,6 +55,10 @@ await_condition/2, await_condition_with_retries/2, + await_condition_ignoring_exceptions/1, + await_condition_ignoring_exceptions/2, + await_condition_with_retries_ignoring_exceptions/2, + eventually/1, eventually/3, consistently/1, consistently/3, @@ -1138,6 +1142,28 @@ await_condition_with_retries(ConditionFun, RetriesLeft) -> ok end. +await_condition_ignoring_exceptions(ConditionFun) -> + await_condition_ignoring_exceptions(ConditionFun, 10_000). + +await_condition_ignoring_exceptions(ConditionFun, Timeout) -> + Retries = ceil(Timeout / 50), + await_condition_with_retries_ignoring_exceptions(ConditionFun, Retries). + +await_condition_with_retries_ignoring_exceptions(_ConditionFun, 0) -> + ct:fail("Condition did not materialize in the expected period of time"); +await_condition_with_retries_ignoring_exceptions(ConditionFun, RetriesLeft) -> + try ConditionFun() of + false -> + timer:sleep(50), + await_condition_with_retries_ignoring_exceptions(ConditionFun, RetriesLeft - 1); + true -> + ok + catch + _:_ -> + timer:sleep(50), + await_condition_with_retries_ignoring_exceptions(ConditionFun, RetriesLeft - 1) + end. + %% Pass in any EUnit test object. Example: %% eventually(?_assertEqual(1, Actual)) eventually({Line, Assertion} = TestObj)