diff --git a/apps/emqx/test/emqx_olp_SUITE.erl b/apps/emqx/test/emqx_olp_SUITE.erl index 7389b259c..2c418ebdf 100644 --- a/apps/emqx/test/emqx_olp_SUITE.erl +++ b/apps/emqx/test/emqx_olp_SUITE.erl @@ -35,8 +35,6 @@ end_per_suite(Config) -> emqx_cth_suite:stop(?config(apps, Config)). init_per_testcase(_, Config) -> - emqx_common_test_helpers:boot_modules(all), - emqx_common_test_helpers:start_apps([]), emqx_olp:enable(), case wait_for(fun() -> lc_sup:whereis_runq_flagman() end, 10) of true -> ok; diff --git a/apps/emqx/test/emqx_quic_multistreams_SUITE.erl b/apps/emqx/test/emqx_quic_multistreams_SUITE.erl index b2205a659..da1ee9191 100644 --- a/apps/emqx/test/emqx_quic_multistreams_SUITE.erl +++ b/apps/emqx/test/emqx_quic_multistreams_SUITE.erl @@ -144,19 +144,35 @@ groups() -> ]. init_per_suite(Config) -> - emqx_common_test_helpers:start_apps([]), - UdpPort = 14567, - start_emqx_quic(UdpPort), - %% Turn off force_shutdown policy. - ShutdownPolicy = emqx_config:get_zone_conf(default, [force_shutdown]), - ct:pal("force shutdown config: ~p", [ShutdownPolicy]), - emqx_config:put_zone_conf(default, [force_shutdown], ShutdownPolicy#{enable := false}), - [{shutdown_policy, ShutdownPolicy}, {port, UdpPort}, {pub_qos, 0}, {sub_qos, 0} | Config]. + Apps = start_emqx(Config), + [{port, 14567}, {pub_qos, 0}, {sub_qos, 0}, {apps, Apps} | Config]. end_per_suite(Config) -> - emqx_config:put_zone_conf(default, [force_shutdown], ?config(shutdown_policy, Config)), - emqx_common_test_helpers:stop_apps([]), - ok. + emqx_cth_suite:stop(?config(apps, Config)). + +start_emqx(Config) -> + emqx_cth_suite:start( + [mk_emqx_spec()], + #{work_dir => emqx_cth_suite:work_dir(Config)} + ). + +stop_emqx(Config) -> + emqx_cth_suite:stop(?config(apps, Config)). + +restart_emqx(Config) -> + ok = stop_emqx(Config), + emqx_cth_suite:start( + [mk_emqx_spec()], + #{work_dir => emqx_cth_suite:work_dir(Config), boot_type => restart} + ). + +mk_emqx_spec() -> + {emqx, + %% Turn off force_shutdown policy. + "force_shutdown.enable = false" + "\n listeners.quic.default {" + "\n enable = true, bind = 14567, acceptors = 16, idle_timeout_ms = 15000" + "\n }"}. init_per_group(pub_qos0, Config) -> [{pub_qos, 0} | Config]; @@ -190,11 +206,6 @@ init_per_group(_, Config) -> end_per_group(_, Config) -> Config. -init_per_testcase(_, Config) -> - emqx_common_test_helpers:start_apps([]), - start_emqx_quic(?config(port, Config)), - Config. - t_quic_sock(Config) -> Port = 4567, SslOpts = [ @@ -1582,9 +1593,13 @@ t_multi_streams_remote_shutdown(Config) -> {quic, _Conn, _Ctrlstream} = proplists:get_value(socket, emqtt:info(C)), - ok = stop_emqx(), - %% Client should be closed - assert_client_die(C, 100, 200). + ok = stop_emqx(Config), + try + %% Client should be closed + assert_client_die(C, 100, 200) + after + restart_emqx(Config) + end. t_multi_streams_remote_shutdown_with_reconnect(Config) -> erlang:process_flag(trap_exit, true), @@ -1636,10 +1651,8 @@ t_multi_streams_remote_shutdown_with_reconnect(Config) -> {quic, _Conn, _Ctrlstream} = proplists:get_value(socket, emqtt:info(C)), - ok = stop_emqx(), + _Apps = restart_emqx(Config), - timer:sleep(200), - start_emqx_quic(?config(port, Config)), ?assert(is_list(emqtt:info(C))), emqtt:stop(C). @@ -2028,16 +2041,6 @@ calc_pkt_id(1, Id) -> calc_pkt_id(2, Id) -> Id. --spec start_emqx_quic(inet:port_number()) -> ok. -start_emqx_quic(UdpPort) -> - emqx_common_test_helpers:start_apps([]), - application:ensure_all_started(quicer), - emqx_common_test_helpers:ensure_quic_listener(?MODULE, UdpPort). - --spec stop_emqx() -> ok. -stop_emqx() -> - emqx_common_test_helpers:stop_apps([]). - %% select a random port picked by OS -spec select_port() -> inet:port_number(). select_port() -> diff --git a/apps/emqx/test/emqx_ratelimiter_SUITE.erl b/apps/emqx/test/emqx_ratelimiter_SUITE.erl index f414c3759..29f268f7c 100644 --- a/apps/emqx/test/emqx_ratelimiter_SUITE.erl +++ b/apps/emqx/test/emqx_ratelimiter_SUITE.erl @@ -47,23 +47,23 @@ all() -> emqx_common_test_helpers:all(?MODULE). init_per_suite(Config) -> - load_conf(), - emqx_common_test_helpers:start_apps([?APP]), - Config. + Apps = emqx_cth_suite:start([emqx], #{work_dir => emqx_cth_suite:work_dir(Config)}), + ok = load_conf(), + [{apps, Apps} | Config]. -end_per_suite(_Config) -> - emqx_common_test_helpers:stop_apps([?APP]). +end_per_suite(Config) -> + emqx_cth_suite:stop(?config(apps, Config)). init_per_testcase(_TestCase, Config) -> - emqx_config:erase(limiter), - load_conf(), + ok = emqx_config:erase(limiter), + ok = load_conf(), Config. end_per_testcase(_TestCase, Config) -> Config. load_conf() -> - ok = emqx_common_test_helpers:load_config(emqx_limiter_schema, ?BASE_CONF). + emqx_common_test_helpers:load_config(emqx_limiter_schema, ?BASE_CONF). init_config() -> emqx_config:init_load(emqx_limiter_schema, ?BASE_CONF). diff --git a/apps/emqx/test/emqx_request_responser_SUITE.erl b/apps/emqx/test/emqx_request_responser_SUITE.erl index 2685b4ac3..299ebf854 100644 --- a/apps/emqx/test/emqx_request_responser_SUITE.erl +++ b/apps/emqx/test/emqx_request_responser_SUITE.erl @@ -22,12 +22,11 @@ -include_lib("common_test/include/ct.hrl"). init_per_suite(Config) -> - emqx_common_test_helpers:boot_modules(all), - emqx_common_test_helpers:start_apps([]), - Config. + Apps = emqx_cth_suite:start([emqx], #{work_dir => emqx_cth_suite:work_dir(Config)}), + [{apps, Apps} | Config]. -end_per_suite(_Config) -> - emqx_common_test_helpers:stop_apps([]). +end_per_suite(Config) -> + emqx_cth_suite:stop(?config(apps, Config)). all() -> emqx_common_test_helpers:all(?MODULE). diff --git a/apps/emqx/test/emqx_shared_sub_SUITE.erl b/apps/emqx/test/emqx_shared_sub_SUITE.erl index 8af3b2190..a5d2567d0 100644 --- a/apps/emqx/test/emqx_shared_sub_SUITE.erl +++ b/apps/emqx/test/emqx_shared_sub_SUITE.erl @@ -49,31 +49,11 @@ all() -> emqx_common_test_helpers:all(?SUITE). init_per_suite(Config) -> - DistPid = - case net_kernel:nodename() of - ignored -> - %% calling `net_kernel:start' without `epmd' - %% running will result in a failure. - emqx_common_test_helpers:start_epmd(), - {ok, Pid} = net_kernel:start(['master@127.0.0.1', longnames]), - ct:pal("start epmd, node name: ~p", [node()]), - Pid; - _ -> - undefined - end, - emqx_common_test_helpers:boot_modules(all), - emqx_common_test_helpers:start_apps([]), - [{dist_pid, DistPid} | Config]. + Apps = emqx_cth_suite:start([emqx], #{work_dir => emqx_cth_suite:work_dir(Config)}), + [{apps, Apps} | Config]. end_per_suite(Config) -> - DistPid = ?config(dist_pid, Config), - case DistPid of - Pid when is_pid(Pid) -> - net_kernel:stop(); - _ -> - ok - end, - emqx_common_test_helpers:stop_apps([]). + emqx_cth_suite:stop(?config(apps, Config)). init_per_testcase(Case, Config) -> try diff --git a/apps/emqx/test/emqx_sup_SUITE.erl b/apps/emqx/test/emqx_sup_SUITE.erl index d2780469e..7a2461c20 100644 --- a/apps/emqx/test/emqx_sup_SUITE.erl +++ b/apps/emqx/test/emqx_sup_SUITE.erl @@ -24,12 +24,11 @@ all() -> emqx_common_test_helpers:all(?MODULE). init_per_suite(Config) -> - emqx_common_test_helpers:boot_modules(all), - emqx_common_test_helpers:start_apps([]), - Config. + Apps = emqx_cth_suite:start([emqx], #{work_dir => emqx_cth_suite:work_dir(Config)}), + [{apps, Apps} | Config]. -end_per_suite(_Config) -> - emqx_common_test_helpers:stop_apps([]). +end_per_suite(Config) -> + emqx_cth_suite:stop(proplists:get_value(apps, Config)). t_child(_) -> ?assertMatch({error, _}, emqx_sup:start_child(undef, worker)),