test: fix a bunch of inter-suite interferences

This commit is contained in:
Thales Macedo Garitezi 2023-09-07 17:13:29 -03:00
parent f1294736b7
commit 64fcdb671d
8 changed files with 134 additions and 134 deletions

View File

@ -91,9 +91,6 @@ app_specs() ->
[ [
emqx_durable_storage, emqx_durable_storage,
{emqx, #{ {emqx, #{
before_start => fun() ->
emqx_app:set_config_loader(?MODULE)
end,
config => #{persistent_session_store => #{ds => true}}, config => #{persistent_session_store => #{ds => true}},
override_env => [{boot_modules, [broker, listeners]}] override_env => [{boot_modules, [broker, listeners]}]
}} }}

View File

@ -21,6 +21,7 @@
-include_lib("emqx/include/emqx_mqtt.hrl"). -include_lib("emqx/include/emqx_mqtt.hrl").
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
-include_lib("common_test/include/ct.hrl").
-define(SYSMON, emqx_sys_mon). -define(SYSMON, emqx_sys_mon).
@ -64,60 +65,66 @@
all() -> emqx_common_test_helpers:all(?MODULE). all() -> emqx_common_test_helpers:all(?MODULE).
init_per_testcase(t_sys_mon, Config) -> init_per_testcase(t_sys_mon = TestCase, Config) ->
emqx_common_test_helpers:boot_modules(all), Apps = emqx_cth_suite:start(
emqx_common_test_helpers:start_apps( [
[], {emqx, #{
fun override_env => [
(emqx) -> {sys_mon, [
application:set_env(emqx, sysmon, [ {busy_dist_port, true},
{busy_dist_port, true}, {busy_port, false},
{busy_port, false}, {large_heap, 8388608},
{large_heap, 8388608}, {long_schedule, 240},
{long_schedule, 240}, {long_gc, 0}
{long_gc, 0} ]}
]), ]
ok; }}
(_) -> ],
ok #{work_dir => emqx_cth_suite:work_dir(TestCase, Config)}
end
), ),
Config; [{apps, Apps} | Config];
init_per_testcase(t_sys_mon2, Config) -> init_per_testcase(t_sys_mon2 = TestCase, Config) ->
emqx_common_test_helpers:boot_modules(all), Apps = emqx_cth_suite:start(
emqx_common_test_helpers:start_apps( [
[], {emqx, #{
fun override_env => [
(emqx) -> {sys_mon, [
application:set_env(emqx, sysmon, [ {busy_dist_port, false},
{busy_dist_port, false}, {busy_port, true},
{busy_port, true}, {large_heap, 8388608},
{large_heap, 8388608}, {long_schedule, 0},
{long_schedule, 0}, {long_gc, 200},
{long_gc, 200}, {nothing, 0}
{nothing, 0} ]}
]), ]
ok; }}
(_) -> ],
ok #{work_dir => emqx_cth_suite:work_dir(TestCase, Config)}
end ),
[{apps, Apps} | Config];
init_per_testcase(t_procinfo = TestCase, Config) ->
Apps = emqx_cth_suite:start(
[emqx],
#{work_dir => emqx_cth_suite:work_dir(TestCase, Config)}
), ),
Config;
init_per_testcase(t_procinfo, Config) ->
emqx_common_test_helpers:boot_modules(all),
emqx_common_test_helpers:start_apps([]),
ok = meck:new(emqx_vm, [passthrough, no_history]), ok = meck:new(emqx_vm, [passthrough, no_history]),
Config; [{apps, Apps} | Config];
init_per_testcase(_, Config) -> init_per_testcase(TestCase, Config) ->
emqx_common_test_helpers:boot_modules(all), Apps = emqx_cth_suite:start(
emqx_common_test_helpers:start_apps([]), [emqx],
Config. #{work_dir => emqx_cth_suite:work_dir(TestCase, Config)}
),
[{apps, Apps} | Config].
end_per_testcase(t_procinfo, _Config) -> end_per_testcase(t_procinfo, Config) ->
Apps = ?config(apps, Config),
ok = meck:unload(emqx_vm), ok = meck:unload(emqx_vm),
emqx_common_test_helpers:stop_apps([]); ok = emqx_cth_suite:stop(Apps),
end_per_testcase(_, _Config) -> ok;
emqx_common_test_helpers:stop_apps([]). end_per_testcase(_, Config) ->
Apps = ?config(apps, Config),
ok = emqx_cth_suite:stop(Apps),
ok.
t_procinfo(_) -> t_procinfo(_) ->
ok = meck:expect(emqx_vm, get_process_info, fun(_) -> [] end), ok = meck:expect(emqx_vm, get_process_info, fun(_) -> [] end),

View File

@ -34,22 +34,15 @@
all() -> emqx_common_test_helpers:all(?MODULE). all() -> emqx_common_test_helpers:all(?MODULE).
init_per_suite(Config) -> init_per_suite(Config) ->
emqx_common_test_helpers:boot_modules(all), Apps = emqx_cth_suite:start(
?check_trace( [emqx],
?wait_async_action( #{work_dir => emqx_cth_suite:work_dir(Config)}
emqx_common_test_helpers:start_apps([]),
#{?snk_kind := listener_started, bind := 1883},
timer:seconds(10)
),
fun(Trace) ->
%% more than one listener
?assertMatch([_ | _], ?of_kind(listener_started, Trace))
end
), ),
Config. [{apps, Apps} | Config].
end_per_suite(_Config) -> end_per_suite(Config) ->
emqx_common_test_helpers:stop_apps([]), Apps = ?config(apps, Config),
ok = emqx_cth_suite:stop(Apps),
ok. ok.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Testcases %% Testcases

View File

@ -32,13 +32,10 @@ all() ->
emqx_common_test_helpers:all(?MODULE). emqx_common_test_helpers:all(?MODULE).
init_per_suite(Config) -> init_per_suite(Config) ->
_ = application:load(emqx),
ok = application:set_env(emqx, data_dir, ?config(priv_dir, Config)),
ok = emqx_config:save_schema_mod_and_names(?MODULE),
Config. Config.
end_per_suite(_Config) -> end_per_suite(_Config) ->
emqx_config:erase_all(). ok.
init_per_testcase(TC, Config) -> init_per_testcase(TC, Config) ->
TCAbsDir = filename:join(?config(priv_dir, Config), TC), TCAbsDir = filename:join(?config(priv_dir, Config), TC),
@ -46,9 +43,10 @@ init_per_testcase(TC, Config) ->
ok = snabbkaffe:start_trace(), ok = snabbkaffe:start_trace(),
[{tc_name, atom_to_list(TC)}, {tc_absdir, TCAbsDir} | Config]. [{tc_name, atom_to_list(TC)}, {tc_absdir, TCAbsDir} | Config].
end_per_testcase(_TC, Config) -> end_per_testcase(_TC, _Config) ->
ok = snabbkaffe:stop(), ok = snabbkaffe:stop(),
ok = application:set_env(emqx, data_dir, ?config(priv_dir, Config)), _ = emqx_schema_hooks:erase_injections(),
_ = emqx_config:erase_all(),
ok. ok.
t_no_orphans(Config) -> t_no_orphans(Config) ->
@ -371,16 +369,18 @@ t_gc_spares_symlinked_datadir(Config) ->
ok = proc_lib:stop(Pid). ok = proc_lib:stop(Pid).
t_gc_active(_Config) -> t_gc_active(Config) ->
ok = emqx_common_test_helpers:boot_modules([]), Apps = emqx_cth_suite:start(
ok = emqx_common_test_helpers:start_apps([]), [emqx],
#{work_dir => emqx_cth_suite:work_dir(?FUNCTION_NAME, Config)}
),
try try
?assertEqual( ?assertEqual(
{ok, []}, {ok, []},
emqx_tls_certfile_gc:run() emqx_tls_certfile_gc:run()
) )
after after
emqx_common_test_helpers:stop_apps([]) emqx_cth_suite:stop(Apps)
end. end.
orphans() -> orphans() ->

View File

@ -34,17 +34,22 @@ all() ->
emqx_common_test_helpers:all(?MODULE). emqx_common_test_helpers:all(?MODULE).
init_per_suite(Config) -> init_per_suite(Config) ->
ok = emqx_common_test_helpers:start_apps([]), Apps = emqx_cth_suite:start(
[emqx],
#{work_dir => emqx_cth_suite:work_dir(Config)}
),
Listeners = emqx_listeners:list(), Listeners = emqx_listeners:list(),
ct:pal("emqx_listeners:list() = ~p~n", [Listeners]), ct:pal("emqx_listeners:list() = ~p~n", [Listeners]),
?assertMatch( ?assertMatch(
[_ | _], [_ | _],
[ID || {ID, #{running := true}} <- Listeners] [ID || {ID, #{running := true}} <- Listeners]
), ),
Config. [{apps, Apps} | Config].
end_per_suite(_Config) -> end_per_suite(Config) ->
emqx_common_test_helpers:stop_apps([]). Apps = ?config(apps, Config),
ok = emqx_cth_suite:stop(Apps),
ok.
init_per_testcase(_, Config) -> init_per_testcase(_, Config) ->
reload(), reload(),

View File

@ -32,12 +32,16 @@
all() -> [t_trace_clientid, t_trace_topic, t_trace_ip_address, t_trace_clientid_utf8]. all() -> [t_trace_clientid, t_trace_topic, t_trace_ip_address, t_trace_clientid_utf8].
init_per_suite(Config) -> init_per_suite(Config) ->
emqx_common_test_helpers:boot_modules(all), Apps = emqx_cth_suite:start(
emqx_common_test_helpers:start_apps([]), [emqx],
Config. #{work_dir => emqx_cth_suite:work_dir(Config)}
),
[{apps, Apps} | Config].
end_per_suite(_Config) -> end_per_suite(Config) ->
emqx_common_test_helpers:stop_apps([]). Apps = ?config(apps, Config),
ok = emqx_cth_suite:stop(Apps),
ok.
init_per_testcase(t_trace_clientid, Config) -> init_per_testcase(t_trace_clientid, Config) ->
init(), init(),

View File

@ -20,12 +20,15 @@
-compile(nowarn_export_all). -compile(nowarn_export_all).
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
-include_lib("common_test/include/ct.hrl").
all() -> emqx_common_test_helpers:all(?MODULE). all() -> emqx_common_test_helpers:all(?MODULE).
init_per_testcase(t_too_many_processes_alarm, Config) -> init_per_testcase(t_too_many_processes_alarm = TestCase, Config) ->
emqx_common_test_helpers:boot_modules(all), Apps = emqx_cth_suite:start(
emqx_common_test_helpers:start_apps([]), [emqx],
#{work_dir => emqx_cth_suite:work_dir(TestCase, Config)}
),
emqx_config:put([sysmon, vm], #{ emqx_config:put([sysmon, vm], #{
process_high_watermark => 0, process_high_watermark => 0,
process_low_watermark => 0, process_low_watermark => 0,
@ -34,14 +37,18 @@ init_per_testcase(t_too_many_processes_alarm, Config) ->
}), }),
ok = supervisor:terminate_child(emqx_sys_sup, emqx_vm_mon), ok = supervisor:terminate_child(emqx_sys_sup, emqx_vm_mon),
{ok, _} = supervisor:restart_child(emqx_sys_sup, emqx_vm_mon), {ok, _} = supervisor:restart_child(emqx_sys_sup, emqx_vm_mon),
Config; [{apps, Apps} | Config];
init_per_testcase(_, Config) -> init_per_testcase(TestCase, Config) ->
emqx_common_test_helpers:boot_modules(all), Apps = emqx_cth_suite:start(
emqx_common_test_helpers:start_apps([]), [emqx],
Config. #{work_dir => emqx_cth_suite:work_dir(TestCase, Config)}
),
[{apps, Apps} | Config].
end_per_testcase(_, _Config) -> end_per_testcase(_, Config) ->
emqx_common_test_helpers:stop_apps([]). Apps = ?config(apps, Config),
ok = emqx_cth_suite:stop(Apps),
ok.
t_too_many_processes_alarm(_) -> t_too_many_processes_alarm(_) ->
timer:sleep(500), timer:sleep(500),

View File

@ -49,6 +49,10 @@ init_per_testcase(TestCase, Config) when
TestCase =/= t_ws_non_check_origin TestCase =/= t_ws_non_check_origin
-> ->
add_bucket(), add_bucket(),
Apps = emqx_cth_suite:start(
[emqx],
#{work_dir => emqx_cth_suite:work_dir(TestCase, Config)}
),
%% Meck Cm %% Meck Cm
ok = meck:new(emqx_cm, [passthrough, no_history, no_link]), ok = meck:new(emqx_cm, [passthrough, no_history, no_link]),
ok = meck:expect(emqx_cm, mark_channel_connected, fun(_) -> ok end), ok = meck:expect(emqx_cm, mark_channel_connected, fun(_) -> ok end),
@ -80,37 +84,32 @@ init_per_testcase(TestCase, Config) when
ok = meck:expect(emqx_metrics, inc, fun(_, _) -> ok end), ok = meck:expect(emqx_metrics, inc, fun(_, _) -> ok end),
ok = meck:expect(emqx_metrics, inc_recv, fun(_) -> ok end), ok = meck:expect(emqx_metrics, inc_recv, fun(_) -> ok end),
ok = meck:expect(emqx_metrics, inc_sent, fun(_) -> ok end), ok = meck:expect(emqx_metrics, inc_sent, fun(_) -> ok end),
PrevConfig = emqx_config:get_listener_conf(ws, default, [websocket]), [{apps, Apps} | Config];
[ init_per_testcase(t_ws_non_check_origin = TestCase, Config) ->
{prev_config, PrevConfig}
| Config
];
init_per_testcase(t_ws_non_check_origin, Config) ->
add_bucket(), add_bucket(),
ok = emqx_common_test_helpers:start_apps([]), Apps = emqx_cth_suite:start(
PrevConfig = emqx_config:get_listener_conf(ws, default, [websocket]), [emqx],
#{work_dir => emqx_cth_suite:work_dir(TestCase, Config)}
),
emqx_config:put_listener_conf(ws, default, [websocket, check_origin_enable], false), emqx_config:put_listener_conf(ws, default, [websocket, check_origin_enable], false),
emqx_config:put_listener_conf(ws, default, [websocket, check_origins], []), emqx_config:put_listener_conf(ws, default, [websocket, check_origins], []),
[ [{apps, Apps} | Config];
{prev_config, PrevConfig} init_per_testcase(TestCase, Config) ->
| Config
];
init_per_testcase(_, Config) ->
add_bucket(), add_bucket(),
PrevConfig = emqx_config:get_listener_conf(ws, default, [websocket]), Apps = emqx_cth_suite:start(
ok = emqx_common_test_helpers:start_apps([]), [emqx],
[ #{work_dir => emqx_cth_suite:work_dir(TestCase, Config)}
{prev_config, PrevConfig} ),
| Config [{apps, Apps} | Config].
].
end_per_testcase(TestCase, _Config) when end_per_testcase(TestCase, Config) when
TestCase =/= t_ws_sub_protocols_mqtt_equivalents, TestCase =/= t_ws_sub_protocols_mqtt_equivalents,
TestCase =/= t_ws_sub_protocols_mqtt, TestCase =/= t_ws_sub_protocols_mqtt,
TestCase =/= t_ws_check_origin, TestCase =/= t_ws_check_origin,
TestCase =/= t_ws_non_check_origin, TestCase =/= t_ws_non_check_origin,
TestCase =/= t_ws_pingreq_before_connected TestCase =/= t_ws_pingreq_before_connected
-> ->
Apps = ?config(apps, Config),
del_bucket(), del_bucket(),
lists:foreach( lists:foreach(
fun meck:unload/1, fun meck:unload/1,
@ -122,32 +121,20 @@ end_per_testcase(TestCase, _Config) when
emqx_hooks, emqx_hooks,
emqx_metrics emqx_metrics
] ]
); ),
ok = emqx_cth_suite:stop(Apps),
ok;
end_per_testcase(t_ws_non_check_origin, Config) -> end_per_testcase(t_ws_non_check_origin, Config) ->
Apps = ?config(apps, Config),
del_bucket(), del_bucket(),
PrevConfig = ?config(prev_config, Config), ok = emqx_cth_suite:stop(Apps),
emqx_config:put_listener_conf(ws, default, [websocket], PrevConfig),
stop_apps(),
ok; ok;
end_per_testcase(_, Config) -> end_per_testcase(_, Config) ->
Apps = ?config(apps, Config),
del_bucket(), del_bucket(),
PrevConfig = ?config(prev_config, Config), ok = emqx_cth_suite:stop(Apps),
emqx_config:put_listener_conf(ws, default, [websocket], PrevConfig),
stop_apps(),
Config. Config.
init_per_suite(Config) ->
emqx_common_test_helpers:start_apps([]),
Config.
end_per_suite(_) ->
emqx_common_test_helpers:stop_apps([]),
ok.
%% FIXME: this is a temp fix to tests share configs.
stop_apps() ->
emqx_common_test_helpers:stop_apps([], #{erase_all_configs => false}).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Test Cases %% Test Cases
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------