Skip to content

Commit fa9a11e

Browse files
committed
Handle race-condition of node not being validated
If it is restartating at the end of the test suite If MIM is restarted asynchronously, simple checking if application is running is not enough. We first need to wait for MIM to actually fully restart. The best place to do it is in end_per_suite. So, if some suite crashes MIM, the rest of suites would quickly fail in init_per_suite (and we need to wait only once)
1 parent 42c3067 commit fa9a11e

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

big_tests/src/cth_validate_nodes.erl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
-export([init/2]).
66

77
-export([pre_init_per_suite/3]).
8+
-export([post_end_per_suite/4]).
89
-export([terminate/1]).
910

10-
-record(state, {}).
11+
-record(state, {node_keys = []}).
1112

1213
%% CT callbacks
1314

@@ -19,8 +20,8 @@ init(_Id, _Opts) ->
1920

2021
pre_init_per_suite(_Suite, Config, State) ->
2122
case distributed_helper:validate_nodes() of
22-
ok ->
23-
{Config, State};
23+
{ok, NodeKeys} ->
24+
{Config, State#state{node_keys = NodeKeys}};
2425
{error, Reason} ->
2526
case os:getenv("SKIP_VALIDATE_NODES") of
2627
"true" ->
@@ -31,5 +32,11 @@ pre_init_per_suite(_Suite, Config, State) ->
3132
end
3233
end.
3334

35+
post_end_per_suite(_SuiteName, _Config, Return, State = #state{node_keys = NodeKeys}) ->
36+
%% In case a suite is restarting the node at the end of the suite execution
37+
%% ensure we wait enough for it actually start
38+
distributed_helper:wait_for_nodes_to_start(NodeKeys),
39+
{Return, State#state{node_keys = []}}.
40+
3441
terminate(_State) ->
3542
ok.

test/common/distributed_helper.erl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,23 @@ lookup_config_opt(Key) ->
208208

209209
%% @doc Checks if MongooseIM nodes are running
210210
validate_nodes() ->
211-
Results = [validate_node(Node) || Node <- get_node_keys()],
211+
validate_nodes(get_node_keys()).
212+
213+
validate_nodes(NodeKeys) ->
214+
Results = [validate_node(Node) || Node <- NodeKeys],
212215
Errors = [Res || Res <- Results, Res =/= ok],
213216
case Errors of
214-
[] -> ok;
217+
[] -> {ok, NodeKeys};
215218
_ -> {error, Errors}
216219
end.
217220

221+
wait_for_nodes_to_start([]) -> ok;
222+
wait_for_nodes_to_start(NodeKeys) ->
223+
wait_helper:wait_until(fun() -> validate_nodes(NodeKeys) end, {ok, NodeKeys},
224+
#{time_left => timer:seconds(20),
225+
sleep_time => 1000,
226+
name => wait_for_nodes_to_start}).
227+
218228
get_node_keys() ->
219229
case os:getenv("TEST_HOSTS") of
220230
false ->

0 commit comments

Comments
 (0)