Skip to content

Commit df8f801

Browse files
authored
Merge pull request #4426 from esl/cth-validate-nodes
Skip every test suite if MIM is not running
2 parents 043d74b + fa9a11e commit df8f801

File tree

6 files changed

+110
-14
lines changed

6 files changed

+110
-14
lines changed

big_tests/default.spec

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@
127127
%% ct_mongoose_hook will:
128128
%% * ensure preset & mim_data_dir values are passed to ct Config
129129
%% * check server's purity after SUITE
130-
{ct_hooks, [ct_groups_summary_hook, ct_tty_hook,
130+
{ct_hooks, [cth_validate_nodes,
131+
ct_groups_summary_hook,
132+
ct_tty_hook,
131133
ct_mongoose_hook,
134+
ct_mongoose_log_hook,
132135
{ct_mongoose_log_hook, [{host, mim2}, {print_init_and_done_for_testcases, false}]},
133136
{ct_mongoose_log_hook, [{host, mim3}, {print_init_and_done_for_testcases, false}]},
134137
ct_progress_hook,
135-
ct_markdown_errors_hook, ct_mongoose_log_hook]}.
136-
137-
%% since test-runner.sh can be executed with the --one-node option,
138-
%% log collection is enabled by default for host mim1 only.
139-
% {ct_hooks, [{ct_mongoose_log_hook,[{host, mim2}, {log, []}]}]}.
138+
ct_markdown_errors_hook
139+
]}.

big_tests/dynamic_domains.spec

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,12 @@
173173
%% ct_mongoose_hook will:
174174
%% * ensure preset & mim_data_dir values are passed to ct Config
175175
%% * check server's purity after SUITE
176-
{ct_hooks, [ct_groups_summary_hook, ct_tty_hook, ct_mongoose_hook, ct_progress_hook,
176+
{ct_hooks, [cth_validate_nodes,
177+
ct_groups_summary_hook,
178+
ct_tty_hook,
179+
ct_mongoose_hook,
180+
ct_progress_hook,
177181
ct_markdown_errors_hook,
178182
ct_mongoose_log_hook,
179183
{ct_mongoose_log_hook, [{host, mim2}, {print_init_and_done_for_testcases, false}]},
180184
{ct_mongoose_log_hook, [{host, mim3}, {print_init_and_done_for_testcases, false}]}]}.
181-
182-
%% since test-runner.sh can be executed with the --one-node option,
183-
%% log collection is enabled by default for host mim1 only.
184-
% {ct_hooks, [{ct_mongoose_log_hook,[{host, mim2}, {log, []}]}]}.

big_tests/src/ct_mongoose_hook.erl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,16 @@ init(_Id, _Opts) ->
4141
{ok, #{}}.
4242

4343
%% @doc Called before init_per_suite is called.
44-
pre_init_per_suite(Suite,Config,State) ->
44+
pre_init_per_suite(Suite, [_|_] = Config, State) ->
4545
Preset = case application:get_env(common_test, test_label) of
4646
{ok, Value} -> Value;
4747
_ -> undefined
4848
end,
4949
DataDir = path_helper:data_dir(Suite, Config),
5050
NewConfig = [{preset, Preset}, {mim_data_dir, DataDir} | Config],
51-
{NewConfig, State}.
51+
{NewConfig, State};
52+
pre_init_per_suite(_Suite, SkipOrFail, State) ->
53+
{SkipOrFail, State}.
5254

5355
%% @doc Called after init_per_suite.
5456
post_init_per_suite(_Suite, _Config, Return, State) ->

big_tests/src/cth_validate_nodes.erl

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
-module(cth_validate_nodes).
2+
3+
%% Callbacks
4+
-export([id/1]).
5+
-export([init/2]).
6+
7+
-export([pre_init_per_suite/3]).
8+
-export([post_end_per_suite/4]).
9+
-export([terminate/1]).
10+
11+
-record(state, {node_keys = []}).
12+
13+
%% CT callbacks
14+
15+
id(_Opts) ->
16+
"cth_validate_nodes_001".
17+
18+
init(_Id, _Opts) ->
19+
{ok, #state{}}.
20+
21+
pre_init_per_suite(_Suite, Config, State) ->
22+
case distributed_helper:validate_nodes() of
23+
{ok, NodeKeys} ->
24+
{Config, State#state{node_keys = NodeKeys}};
25+
{error, Reason} ->
26+
case os:getenv("SKIP_VALIDATE_NODES") of
27+
"true" ->
28+
ct:pal("Skip failing with ~p in ct_check_rpc_nodes", [Reason]),
29+
{Config, State};
30+
_ ->
31+
{{fail, Reason}, State}
32+
end
33+
end.
34+
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+
41+
terminate(_State) ->
42+
ok.

test/common/distributed_helper.erl

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ add_node_to_cluster(Node, Config) ->
3939
end,
4040
Config.
4141

42-
add_node_to_mnesia_cluster(Node, Config) ->
42+
add_node_to_mnesia_cluster(Node, _Config) ->
4343
ClusterMemberNode = maps:get(node, mim()),
4444
ok = rpc(Node#{timeout => cluster_op_timeout()},
4545
mongoose_cluster, join, [ClusterMemberNode]),
@@ -205,3 +205,43 @@ subhost_pattern(SubhostTemplate) ->
205205

206206
lookup_config_opt(Key) ->
207207
rpc(mim(), mongoose_config, lookup_opt, [Key]).
208+
209+
%% @doc Checks if MongooseIM nodes are running
210+
validate_nodes() ->
211+
validate_nodes(get_node_keys()).
212+
213+
validate_nodes(NodeKeys) ->
214+
Results = [validate_node(Node) || Node <- NodeKeys],
215+
Errors = [Res || Res <- Results, Res =/= ok],
216+
case Errors of
217+
[] -> {ok, NodeKeys};
218+
_ -> {error, Errors}
219+
end.
220+
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+
228+
get_node_keys() ->
229+
case os:getenv("TEST_HOSTS") of
230+
false ->
231+
[NodeKey || {NodeKey, _Opts} <- ct:get_config(hosts)];
232+
EnvValue -> %% EnvValue examples are "mim" or "mim mim2"
233+
BinHosts = binary:split(iolist_to_binary(EnvValue), <<" ">>, [global]),
234+
[binary_to_atom(Node, utf8) || Node <- BinHosts]
235+
end.
236+
237+
validate_node(NodeKey) ->
238+
Spec = #{node := Node} = rpc_spec(NodeKey),
239+
try rpc(Spec, application, which_applications, []) of
240+
Loaded ->
241+
case lists:keymember(mongooseim, 1, Loaded) of
242+
true -> ok;
243+
false -> {validate_node_failed, mongooseim_not_running, Node}
244+
end
245+
catch error:{badrpc, Reason} ->
246+
{validate_node_failed, {badrpc, Reason}, Node}
247+
end.

tools/test-runner.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Options:
3737
--skip-start-nodes -- do not start nodes before big tests
3838
--skip-stop-nodes -- do not stop nodes after big tests
3939
--skip-setup-db -- do not start any databases, the same as "--db --" option
40+
--skip-validate-nodes -- do not check if MongooseIM is running
4041
--no-parallel -- run most commands in sequence
4142
--tls-dist -- enable encryption between nodes in big tests
4243
--verbose -- print script output
@@ -115,6 +116,9 @@ Script examples:
115116
Sets dev-nodes and test-hosts to empty lists
116117
Reruns mam_SUITE
117118
119+
./tools/test-runner.sh --skip-small-tests --skip-start-nodes --skip-validate-nodes -- connect
120+
Continues test execution even if MongooseIM is not running on all nodes
121+
118122
./tools/test-runner.sh --rerun-big-tests -- mam
119123
The same command as above
120124
@@ -309,6 +313,7 @@ SELECTED_TESTS=()
309313
STOP_SCRIPT=false
310314
SKIP_DB_SETUP=false
311315
DB_FROM_PRESETS=true
316+
SKIP_VALIDATE_NODES=false
312317

313318
# Parse command line arguments
314319
# Prefer arguments to env variables
@@ -353,6 +358,11 @@ case $key in
353358
DB_FROM_PRESETS=false
354359
;;
355360

361+
--skip-validate-nodes)
362+
shift # past argument
363+
SKIP_VALIDATE_NODES=true
364+
;;
365+
356366
# Similar how we parse --db option
357367
--preset)
358368
shift # past argument
@@ -635,6 +645,7 @@ export TESTSPEC="auto_big_tests.spec"
635645
export START_NODES="$START_NODES"
636646
export STOP_NODES="$STOP_NODES"
637647
export PAUSE_BEFORE_BIG_TESTS="$PAUSE_BEFORE_BIG_TESTS"
648+
export SKIP_VALIDATE_NODES="$SKIP_VALIDATE_NODES"
638649

639650
# Debug printing
640651
echo "Variables:"
@@ -653,6 +664,7 @@ echo " TESTSPEC=$TESTSPEC"
653664
echo " TLS_DIST=$TLS_DIST"
654665
echo " START_NODES=$START_NODES"
655666
echo " STOP_NODES=$STOP_NODES"
667+
echo " SKIP_VALIDATE_NODES=$SKIP_VALIDATE_NODES"
656668
echo ""
657669

658670

0 commit comments

Comments
 (0)