Skip to content

Commit 76e8c8e

Browse files
More reliable drain and revive command assertions
(cherry picked from commit 6f17c6c)
1 parent b558316 commit 76e8c8e

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

deps/rabbitmq_cli/test/test_helper.exs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,23 @@ defmodule TestHelper do
250250
end
251251
end
252252

253+
def await_condition(fun, timeout) do
254+
retries = Integer.floor_div(timeout, 50)
255+
await_condition_with_retries(fun, retries)
256+
end
257+
258+
def await_condition_with_retries(_fun, 0) do
259+
throw({:error, "Condition did not materialize"})
260+
end
261+
def await_condition_with_retries(fun, retries_left) do
262+
case fun.() do
263+
true -> :ok
264+
_ ->
265+
:timer.sleep(50)
266+
await_condition_with_retries(fun, retries_left - 1)
267+
end
268+
end
269+
253270
def is_rabbitmq_app_running() do
254271
:rabbit_misc.rpc_call(get_rabbit_hostname(), :rabbit, :is_booted, [])
255272
end

deps/rabbitmq_cli/test/upgrade/drain_command_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ defmodule DrainCommandTest do
5050
test "run: puts target node into maintenance mode", context do
5151
assert not is_draining_node()
5252
assert :ok == @command.run([], context[:opts])
53-
assert is_draining_node()
5453

54+
await_condition(fn -> is_draining_node() end, 7000)
5555
revive_node()
5656
end
5757
end

deps/rabbitmq_cli/test/upgrade/revive_command_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ defmodule ReviveCommandTest do
5050
test "run: puts target node into regular operating mode", context do
5151
assert not is_draining_node()
5252
drain_node()
53-
assert is_draining_node()
53+
await_condition(fn -> is_draining_node() end, 7000)
5454
assert :ok == @command.run([], context[:opts])
55-
assert not is_draining_node()
55+
await_condition(fn -> not is_draining_node() end, 7000)
5656
end
5757
end

0 commit comments

Comments
 (0)