Skip to content

Commit be3aa5b

Browse files
Merge pull request #14274 from rabbitmq/mergify/bp/v4.1.x/pr-14270
Introduce rabbit_ct_helpers:await_condition_* helpers which ignore exceptions (backport #14270)
2 parents c6e7eec + 4eb43d0 commit be3aa5b

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

deps/rabbitmq_ct_helpers/src/rabbit_ct_helpers.erl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
await_condition/2,
5656
await_condition_with_retries/2,
5757

58+
await_condition_ignoring_exceptions/1,
59+
await_condition_ignoring_exceptions/2,
60+
await_condition_with_retries_ignoring_exceptions/2,
61+
5862
eventually/1, eventually/3,
5963
consistently/1, consistently/3,
6064

@@ -1138,6 +1142,28 @@ await_condition_with_retries(ConditionFun, RetriesLeft) ->
11381142
ok
11391143
end.
11401144

1145+
await_condition_ignoring_exceptions(ConditionFun) ->
1146+
await_condition_ignoring_exceptions(ConditionFun, 10_000).
1147+
1148+
await_condition_ignoring_exceptions(ConditionFun, Timeout) ->
1149+
Retries = ceil(Timeout / 50),
1150+
await_condition_with_retries_ignoring_exceptions(ConditionFun, Retries).
1151+
1152+
await_condition_with_retries_ignoring_exceptions(_ConditionFun, 0) ->
1153+
ct:fail("Condition did not materialize in the expected period of time");
1154+
await_condition_with_retries_ignoring_exceptions(ConditionFun, RetriesLeft) ->
1155+
try ConditionFun() of
1156+
false ->
1157+
timer:sleep(50),
1158+
await_condition_with_retries_ignoring_exceptions(ConditionFun, RetriesLeft - 1);
1159+
true ->
1160+
ok
1161+
catch
1162+
_:_ ->
1163+
timer:sleep(50),
1164+
await_condition_with_retries_ignoring_exceptions(ConditionFun, RetriesLeft - 1)
1165+
end.
1166+
11411167
%% Pass in any EUnit test object. Example:
11421168
%% eventually(?_assertEqual(1, Actual))
11431169
eventually({Line, Assertion} = TestObj)

0 commit comments

Comments
 (0)