test(conf): update and simplify some testcases

This commit is contained in:
Andrew Mayorov 2024-02-13 18:49:29 +01:00
parent 0a9cbe3080
commit 841fdea124
No known key found for this signature in database
GPG Key ID: 2837C62ACFBFED5D
3 changed files with 32 additions and 43 deletions

View File

@ -38,7 +38,7 @@
%% in `end_per_suite/1` or `end_per_group/2`) with the result from step 2.
-module(emqx_cth_cluster).
-export([start/1, start/2, restart/2]).
-export([start/1, start/2, restart/1, restart/2]).
-export([stop/1, stop_node/1]).
-export([start_bare_nodes/1, start_bare_nodes/2]).
@ -162,6 +162,9 @@ wait_clustered([Node | Nodes] = All, Check, Deadline) ->
wait_clustered(All, Check, Deadline)
end.
restart(NodeSpec) ->
restart(maps:get(name, NodeSpec), NodeSpec).
restart(Node, Spec) ->
ct:pal("Stopping peer node ~p", [Node]),
ok = emqx_cth_peer:stop(Node),

View File

@ -42,10 +42,8 @@ suite() -> [{timetrap, {minutes, 5}}].
groups() -> [].
init_per_suite(Config) ->
application:load(emqx_conf),
ok = ekka:start(),
ok = emqx_common_test_helpers:start_apps([]),
ok = mria_rlog:wait_for_shards([?CLUSTER_RPC_SHARD], infinity),
ok = mria:wait_for_tables(emqx_cluster_rpc:create_tables()),
ok = emqx_config:put([node, cluster_call, retry_interval], 1000),
meck:new(emqx_alarm, [non_strict, passthrough, no_link]),
meck:expect(emqx_alarm, activate, 3, ok),
@ -56,10 +54,6 @@ init_per_suite(Config) ->
end_per_suite(_Config) ->
ok = emqx_common_test_helpers:stop_apps([]),
ekka:stop(),
mria:stop(),
meck:unload(mria),
mria_mnesia:delete_schema(),
meck:unload(emqx_alarm),
ok.

View File

@ -27,9 +27,10 @@ all() ->
t_copy_conf_override_on_restarts(Config) ->
ct:timetrap({seconds, 120}),
snabbkaffe:fix_ct_logging(),
Cluster = cluster(
[cluster_spec({core, 1}), cluster_spec({core, 2}), cluster_spec({core, 3})], Config
?FUNCTION_NAME,
[cluster_spec({core, 1}), cluster_spec({core, 2}), cluster_spec({core, 3})],
Config
),
%% 1. Start all nodes
@ -42,7 +43,7 @@ t_copy_conf_override_on_restarts(Config) ->
%% 3. Restart nodes in the same order. This should not
%% crash and eventually all nodes should be ready.
start_cluster_async(Cluster),
restart_cluster_async(Cluster),
timer:sleep(15000),
@ -54,11 +55,12 @@ t_copy_conf_override_on_restarts(Config) ->
end.
t_copy_new_data_dir(Config) ->
net_kernel:start(['master1@127.0.0.1', longnames]),
ct:timetrap({seconds, 120}),
snabbkaffe:fix_ct_logging(),
Cluster = cluster(
[cluster_spec({core, 4}), cluster_spec({core, 5}), cluster_spec({core, 6})], Config
?FUNCTION_NAME,
[cluster_spec({core, 4}), cluster_spec({core, 5}), cluster_spec({core, 6})],
Config
),
%% 1. Start all nodes
@ -81,11 +83,11 @@ t_copy_new_data_dir(Config) ->
end.
t_copy_deprecated_data_dir(Config) ->
net_kernel:start(['master2@127.0.0.1', longnames]),
ct:timetrap({seconds, 120}),
snabbkaffe:fix_ct_logging(),
Cluster = cluster(
[cluster_spec({core, 7}), cluster_spec({core, 8}), cluster_spec({core, 9})], Config
?FUNCTION_NAME,
[cluster_spec({core, 7}), cluster_spec({core, 8}), cluster_spec({core, 9})],
Config
),
%% 1. Start all nodes
@ -108,11 +110,11 @@ t_copy_deprecated_data_dir(Config) ->
end.
t_no_copy_from_newer_version_node(Config) ->
net_kernel:start(['master2@127.0.0.1', longnames]),
ct:timetrap({seconds, 120}),
snabbkaffe:fix_ct_logging(),
Cluster = cluster(
[cluster_spec({core, 10}), cluster_spec({core, 11}), cluster_spec({core, 12})], Config
?FUNCTION_NAME,
[cluster_spec({core, 10}), cluster_spec({core, 11}), cluster_spec({core, 12})],
Config
),
OKs = [ok, ok, ok],
[First | Rest] = Nodes = start_cluster(Cluster),
@ -222,39 +224,29 @@ assert_config_load_done(Nodes) ->
).
stop_cluster(Nodes) ->
emqx_utils:pmap(fun emqx_common_test_helpers:stop_peer/1, Nodes).
emqx_cth_cluster:stop(Nodes).
start_cluster(Specs) ->
[emqx_common_test_helpers:start_peer(Name, Opts) || {Name, Opts} <- Specs].
emqx_cth_cluster:start(Specs).
start_cluster_async(Specs) ->
restart_cluster_async(Specs) ->
[
begin
Opts1 = maps:remove(join_to, Opts),
spawn_link(fun() -> emqx_common_test_helpers:start_peer(Name, Opts1) end),
timer:sleep(7_000)
_Pid = spawn_link(emqx_cth_cluster, restart, [Spec]),
timer:sleep(1_000)
end
|| {Name, Opts} <- Specs
|| Spec <- Specs
].
cluster(Specs, Config) ->
PrivDataDir = ?config(priv_dir, Config),
Env = [
{emqx, boot_modules, []}
cluster(TC, Specs, Config) ->
Apps = [
{emqx, #{override_env => [{boot_modules, [broker]}]}},
{emqx_conf, #{}}
],
emqx_common_test_helpers:emqx_cluster(Specs, [
{env, Env},
{apps, [emqx_conf]},
{load_schema, false},
{priv_data_dir, PrivDataDir},
{env_handler, fun
(emqx) ->
application:set_env(emqx, boot_modules, []),
ok;
(_) ->
ok
end}
]).
emqx_cth_cluster:mk_nodespecs(
[{Name, #{role => Role, apps => Apps}} || {Role, Name} <- Specs],
#{work_dir => emqx_cth_suite:work_dir(TC, Config)}
).
cluster_spec({Type, Num}) ->
{Type, list_to_atom(atom_to_list(?MODULE) ++ integer_to_list(Num))}.