test(conf): update and simplify some testcases
This commit is contained in:
parent
0a9cbe3080
commit
841fdea124
|
@ -38,7 +38,7 @@
|
||||||
%% in `end_per_suite/1` or `end_per_group/2`) with the result from step 2.
|
%% in `end_per_suite/1` or `end_per_group/2`) with the result from step 2.
|
||||||
-module(emqx_cth_cluster).
|
-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([stop/1, stop_node/1]).
|
||||||
|
|
||||||
-export([start_bare_nodes/1, start_bare_nodes/2]).
|
-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)
|
wait_clustered(All, Check, Deadline)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
restart(NodeSpec) ->
|
||||||
|
restart(maps:get(name, NodeSpec), NodeSpec).
|
||||||
|
|
||||||
restart(Node, Spec) ->
|
restart(Node, Spec) ->
|
||||||
ct:pal("Stopping peer node ~p", [Node]),
|
ct:pal("Stopping peer node ~p", [Node]),
|
||||||
ok = emqx_cth_peer:stop(Node),
|
ok = emqx_cth_peer:stop(Node),
|
||||||
|
|
|
@ -42,10 +42,8 @@ suite() -> [{timetrap, {minutes, 5}}].
|
||||||
groups() -> [].
|
groups() -> [].
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
application:load(emqx_conf),
|
|
||||||
ok = ekka:start(),
|
|
||||||
ok = emqx_common_test_helpers:start_apps([]),
|
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),
|
ok = emqx_config:put([node, cluster_call, retry_interval], 1000),
|
||||||
meck:new(emqx_alarm, [non_strict, passthrough, no_link]),
|
meck:new(emqx_alarm, [non_strict, passthrough, no_link]),
|
||||||
meck:expect(emqx_alarm, activate, 3, ok),
|
meck:expect(emqx_alarm, activate, 3, ok),
|
||||||
|
@ -56,10 +54,6 @@ init_per_suite(Config) ->
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(_Config) ->
|
||||||
ok = emqx_common_test_helpers:stop_apps([]),
|
ok = emqx_common_test_helpers:stop_apps([]),
|
||||||
ekka:stop(),
|
|
||||||
mria:stop(),
|
|
||||||
meck:unload(mria),
|
|
||||||
mria_mnesia:delete_schema(),
|
|
||||||
meck:unload(emqx_alarm),
|
meck:unload(emqx_alarm),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
|
|
@ -27,9 +27,10 @@ all() ->
|
||||||
|
|
||||||
t_copy_conf_override_on_restarts(Config) ->
|
t_copy_conf_override_on_restarts(Config) ->
|
||||||
ct:timetrap({seconds, 120}),
|
ct:timetrap({seconds, 120}),
|
||||||
snabbkaffe:fix_ct_logging(),
|
|
||||||
Cluster = cluster(
|
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
|
%% 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
|
%% 3. Restart nodes in the same order. This should not
|
||||||
%% crash and eventually all nodes should be ready.
|
%% crash and eventually all nodes should be ready.
|
||||||
start_cluster_async(Cluster),
|
restart_cluster_async(Cluster),
|
||||||
|
|
||||||
timer:sleep(15000),
|
timer:sleep(15000),
|
||||||
|
|
||||||
|
@ -54,11 +55,12 @@ t_copy_conf_override_on_restarts(Config) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
t_copy_new_data_dir(Config) ->
|
t_copy_new_data_dir(Config) ->
|
||||||
net_kernel:start(['master1@127.0.0.1', longnames]),
|
|
||||||
ct:timetrap({seconds, 120}),
|
ct:timetrap({seconds, 120}),
|
||||||
snabbkaffe:fix_ct_logging(),
|
snabbkaffe:fix_ct_logging(),
|
||||||
Cluster = cluster(
|
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
|
%% 1. Start all nodes
|
||||||
|
@ -81,11 +83,11 @@ t_copy_new_data_dir(Config) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
t_copy_deprecated_data_dir(Config) ->
|
t_copy_deprecated_data_dir(Config) ->
|
||||||
net_kernel:start(['master2@127.0.0.1', longnames]),
|
|
||||||
ct:timetrap({seconds, 120}),
|
ct:timetrap({seconds, 120}),
|
||||||
snabbkaffe:fix_ct_logging(),
|
|
||||||
Cluster = cluster(
|
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
|
%% 1. Start all nodes
|
||||||
|
@ -108,11 +110,11 @@ t_copy_deprecated_data_dir(Config) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
t_no_copy_from_newer_version_node(Config) ->
|
t_no_copy_from_newer_version_node(Config) ->
|
||||||
net_kernel:start(['master2@127.0.0.1', longnames]),
|
|
||||||
ct:timetrap({seconds, 120}),
|
ct:timetrap({seconds, 120}),
|
||||||
snabbkaffe:fix_ct_logging(),
|
|
||||||
Cluster = cluster(
|
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],
|
OKs = [ok, ok, ok],
|
||||||
[First | Rest] = Nodes = start_cluster(Cluster),
|
[First | Rest] = Nodes = start_cluster(Cluster),
|
||||||
|
@ -222,39 +224,29 @@ assert_config_load_done(Nodes) ->
|
||||||
).
|
).
|
||||||
|
|
||||||
stop_cluster(Nodes) ->
|
stop_cluster(Nodes) ->
|
||||||
emqx_utils:pmap(fun emqx_common_test_helpers:stop_peer/1, Nodes).
|
emqx_cth_cluster:stop(Nodes).
|
||||||
|
|
||||||
start_cluster(Specs) ->
|
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
|
begin
|
||||||
Opts1 = maps:remove(join_to, Opts),
|
_Pid = spawn_link(emqx_cth_cluster, restart, [Spec]),
|
||||||
spawn_link(fun() -> emqx_common_test_helpers:start_peer(Name, Opts1) end),
|
timer:sleep(1_000)
|
||||||
timer:sleep(7_000)
|
|
||||||
end
|
end
|
||||||
|| {Name, Opts} <- Specs
|
|| Spec <- Specs
|
||||||
].
|
].
|
||||||
|
|
||||||
cluster(Specs, Config) ->
|
cluster(TC, Specs, Config) ->
|
||||||
PrivDataDir = ?config(priv_dir, Config),
|
Apps = [
|
||||||
Env = [
|
{emqx, #{override_env => [{boot_modules, [broker]}]}},
|
||||||
{emqx, boot_modules, []}
|
{emqx_conf, #{}}
|
||||||
],
|
],
|
||||||
emqx_common_test_helpers:emqx_cluster(Specs, [
|
emqx_cth_cluster:mk_nodespecs(
|
||||||
{env, Env},
|
[{Name, #{role => Role, apps => Apps}} || {Role, Name} <- Specs],
|
||||||
{apps, [emqx_conf]},
|
#{work_dir => emqx_cth_suite:work_dir(TC, Config)}
|
||||||
{load_schema, false},
|
).
|
||||||
{priv_data_dir, PrivDataDir},
|
|
||||||
{env_handler, fun
|
|
||||||
(emqx) ->
|
|
||||||
application:set_env(emqx, boot_modules, []),
|
|
||||||
ok;
|
|
||||||
(_) ->
|
|
||||||
ok
|
|
||||||
end}
|
|
||||||
]).
|
|
||||||
|
|
||||||
cluster_spec({Type, Num}) ->
|
cluster_spec({Type, Num}) ->
|
||||||
{Type, list_to_atom(atom_to_list(?MODULE) ++ integer_to_list(Num))}.
|
{Type, list_to_atom(atom_to_list(?MODULE) ++ integer_to_list(Num))}.
|
||||||
|
|
Loading…
Reference in New Issue