From 841fdea1246a9e4568a8476735e09870d300fb79 Mon Sep 17 00:00:00 2001 From: Andrew Mayorov Date: Tue, 13 Feb 2024 18:49:29 +0100 Subject: [PATCH] test(conf): update and simplify some testcases --- apps/emqx/test/emqx_cth_cluster.erl | 5 +- .../emqx_conf/test/emqx_cluster_rpc_SUITE.erl | 8 +-- apps/emqx_conf/test/emqx_conf_app_SUITE.erl | 62 ++++++++----------- 3 files changed, 32 insertions(+), 43 deletions(-) diff --git a/apps/emqx/test/emqx_cth_cluster.erl b/apps/emqx/test/emqx_cth_cluster.erl index 0ac597ff6..54e399795 100644 --- a/apps/emqx/test/emqx_cth_cluster.erl +++ b/apps/emqx/test/emqx_cth_cluster.erl @@ -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), diff --git a/apps/emqx_conf/test/emqx_cluster_rpc_SUITE.erl b/apps/emqx_conf/test/emqx_cluster_rpc_SUITE.erl index 99a0766ec..09e3d7517 100644 --- a/apps/emqx_conf/test/emqx_cluster_rpc_SUITE.erl +++ b/apps/emqx_conf/test/emqx_cluster_rpc_SUITE.erl @@ -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. diff --git a/apps/emqx_conf/test/emqx_conf_app_SUITE.erl b/apps/emqx_conf/test/emqx_conf_app_SUITE.erl index 155489af7..3ec897e08 100644 --- a/apps/emqx_conf/test/emqx_conf_app_SUITE.erl +++ b/apps/emqx_conf/test/emqx_conf_app_SUITE.erl @@ -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))}.