test: fix a bunch of inter-suite interferences
This commit is contained in:
parent
f1294736b7
commit
64fcdb671d
|
@ -91,9 +91,6 @@ app_specs() ->
|
|||
[
|
||||
emqx_durable_storage,
|
||||
{emqx, #{
|
||||
before_start => fun() ->
|
||||
emqx_app:set_config_loader(?MODULE)
|
||||
end,
|
||||
config => #{persistent_session_store => #{ds => true}},
|
||||
override_env => [{boot_modules, [broker, listeners]}]
|
||||
}}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
-include_lib("emqx/include/emqx_mqtt.hrl").
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
-include_lib("common_test/include/ct.hrl").
|
||||
|
||||
-define(SYSMON, emqx_sys_mon).
|
||||
|
||||
|
@ -64,60 +65,66 @@
|
|||
|
||||
all() -> emqx_common_test_helpers:all(?MODULE).
|
||||
|
||||
init_per_testcase(t_sys_mon, Config) ->
|
||||
emqx_common_test_helpers:boot_modules(all),
|
||||
emqx_common_test_helpers:start_apps(
|
||||
[],
|
||||
fun
|
||||
(emqx) ->
|
||||
application:set_env(emqx, sysmon, [
|
||||
{busy_dist_port, true},
|
||||
{busy_port, false},
|
||||
{large_heap, 8388608},
|
||||
{long_schedule, 240},
|
||||
{long_gc, 0}
|
||||
]),
|
||||
ok;
|
||||
(_) ->
|
||||
ok
|
||||
end
|
||||
init_per_testcase(t_sys_mon = TestCase, Config) ->
|
||||
Apps = emqx_cth_suite:start(
|
||||
[
|
||||
{emqx, #{
|
||||
override_env => [
|
||||
{sys_mon, [
|
||||
{busy_dist_port, true},
|
||||
{busy_port, false},
|
||||
{large_heap, 8388608},
|
||||
{long_schedule, 240},
|
||||
{long_gc, 0}
|
||||
]}
|
||||
]
|
||||
}}
|
||||
],
|
||||
#{work_dir => emqx_cth_suite:work_dir(TestCase, Config)}
|
||||
),
|
||||
Config;
|
||||
init_per_testcase(t_sys_mon2, Config) ->
|
||||
emqx_common_test_helpers:boot_modules(all),
|
||||
emqx_common_test_helpers:start_apps(
|
||||
[],
|
||||
fun
|
||||
(emqx) ->
|
||||
application:set_env(emqx, sysmon, [
|
||||
{busy_dist_port, false},
|
||||
{busy_port, true},
|
||||
{large_heap, 8388608},
|
||||
{long_schedule, 0},
|
||||
{long_gc, 200},
|
||||
{nothing, 0}
|
||||
]),
|
||||
ok;
|
||||
(_) ->
|
||||
ok
|
||||
end
|
||||
[{apps, Apps} | Config];
|
||||
init_per_testcase(t_sys_mon2 = TestCase, Config) ->
|
||||
Apps = emqx_cth_suite:start(
|
||||
[
|
||||
{emqx, #{
|
||||
override_env => [
|
||||
{sys_mon, [
|
||||
{busy_dist_port, false},
|
||||
{busy_port, true},
|
||||
{large_heap, 8388608},
|
||||
{long_schedule, 0},
|
||||
{long_gc, 200},
|
||||
{nothing, 0}
|
||||
]}
|
||||
]
|
||||
}}
|
||||
],
|
||||
#{work_dir => emqx_cth_suite:work_dir(TestCase, Config)}
|
||||
),
|
||||
[{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]),
|
||||
Config;
|
||||
init_per_testcase(_, Config) ->
|
||||
emqx_common_test_helpers:boot_modules(all),
|
||||
emqx_common_test_helpers:start_apps([]),
|
||||
Config.
|
||||
[{apps, Apps} | Config];
|
||||
init_per_testcase(TestCase, Config) ->
|
||||
Apps = emqx_cth_suite:start(
|
||||
[emqx],
|
||||
#{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),
|
||||
emqx_common_test_helpers:stop_apps([]);
|
||||
end_per_testcase(_, _Config) ->
|
||||
emqx_common_test_helpers:stop_apps([]).
|
||||
ok = emqx_cth_suite:stop(Apps),
|
||||
ok;
|
||||
end_per_testcase(_, Config) ->
|
||||
Apps = ?config(apps, Config),
|
||||
ok = emqx_cth_suite:stop(Apps),
|
||||
ok.
|
||||
|
||||
t_procinfo(_) ->
|
||||
ok = meck:expect(emqx_vm, get_process_info, fun(_) -> [] end),
|
||||
|
|
|
@ -34,22 +34,15 @@
|
|||
all() -> emqx_common_test_helpers:all(?MODULE).
|
||||
|
||||
init_per_suite(Config) ->
|
||||
emqx_common_test_helpers:boot_modules(all),
|
||||
?check_trace(
|
||||
?wait_async_action(
|
||||
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
|
||||
Apps = emqx_cth_suite:start(
|
||||
[emqx],
|
||||
#{work_dir => emqx_cth_suite:work_dir(Config)}
|
||||
),
|
||||
Config.
|
||||
[{apps, Apps} | Config].
|
||||
|
||||
end_per_suite(_Config) ->
|
||||
emqx_common_test_helpers:stop_apps([]),
|
||||
end_per_suite(Config) ->
|
||||
Apps = ?config(apps, Config),
|
||||
ok = emqx_cth_suite:stop(Apps),
|
||||
ok.
|
||||
%%--------------------------------------------------------------------
|
||||
%% Testcases
|
||||
|
|
|
@ -32,13 +32,10 @@ all() ->
|
|||
emqx_common_test_helpers:all(?MODULE).
|
||||
|
||||
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.
|
||||
|
||||
end_per_suite(_Config) ->
|
||||
emqx_config:erase_all().
|
||||
ok.
|
||||
|
||||
init_per_testcase(TC, Config) ->
|
||||
TCAbsDir = filename:join(?config(priv_dir, Config), TC),
|
||||
|
@ -46,9 +43,10 @@ init_per_testcase(TC, Config) ->
|
|||
ok = snabbkaffe:start_trace(),
|
||||
[{tc_name, atom_to_list(TC)}, {tc_absdir, TCAbsDir} | Config].
|
||||
|
||||
end_per_testcase(_TC, Config) ->
|
||||
end_per_testcase(_TC, _Config) ->
|
||||
ok = snabbkaffe:stop(),
|
||||
ok = application:set_env(emqx, data_dir, ?config(priv_dir, Config)),
|
||||
_ = emqx_schema_hooks:erase_injections(),
|
||||
_ = emqx_config:erase_all(),
|
||||
ok.
|
||||
|
||||
t_no_orphans(Config) ->
|
||||
|
@ -371,16 +369,18 @@ t_gc_spares_symlinked_datadir(Config) ->
|
|||
|
||||
ok = proc_lib:stop(Pid).
|
||||
|
||||
t_gc_active(_Config) ->
|
||||
ok = emqx_common_test_helpers:boot_modules([]),
|
||||
ok = emqx_common_test_helpers:start_apps([]),
|
||||
t_gc_active(Config) ->
|
||||
Apps = emqx_cth_suite:start(
|
||||
[emqx],
|
||||
#{work_dir => emqx_cth_suite:work_dir(?FUNCTION_NAME, Config)}
|
||||
),
|
||||
try
|
||||
?assertEqual(
|
||||
{ok, []},
|
||||
emqx_tls_certfile_gc:run()
|
||||
)
|
||||
after
|
||||
emqx_common_test_helpers:stop_apps([])
|
||||
emqx_cth_suite:stop(Apps)
|
||||
end.
|
||||
|
||||
orphans() ->
|
||||
|
|
|
@ -34,17 +34,22 @@ all() ->
|
|||
emqx_common_test_helpers:all(?MODULE).
|
||||
|
||||
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(),
|
||||
ct:pal("emqx_listeners:list() = ~p~n", [Listeners]),
|
||||
?assertMatch(
|
||||
[_ | _],
|
||||
[ID || {ID, #{running := true}} <- Listeners]
|
||||
),
|
||||
Config.
|
||||
[{apps, Apps} | Config].
|
||||
|
||||
end_per_suite(_Config) ->
|
||||
emqx_common_test_helpers:stop_apps([]).
|
||||
end_per_suite(Config) ->
|
||||
Apps = ?config(apps, Config),
|
||||
ok = emqx_cth_suite:stop(Apps),
|
||||
ok.
|
||||
|
||||
init_per_testcase(_, Config) ->
|
||||
reload(),
|
||||
|
|
|
@ -32,12 +32,16 @@
|
|||
all() -> [t_trace_clientid, t_trace_topic, t_trace_ip_address, t_trace_clientid_utf8].
|
||||
|
||||
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) ->
|
||||
Apps = ?config(apps, Config),
|
||||
ok = emqx_cth_suite:stop(Apps),
|
||||
ok.
|
||||
|
||||
init_per_testcase(t_trace_clientid, Config) ->
|
||||
init(),
|
||||
|
|
|
@ -20,12 +20,15 @@
|
|||
-compile(nowarn_export_all).
|
||||
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
-include_lib("common_test/include/ct.hrl").
|
||||
|
||||
all() -> emqx_common_test_helpers:all(?MODULE).
|
||||
|
||||
init_per_testcase(t_too_many_processes_alarm, Config) ->
|
||||
emqx_common_test_helpers:boot_modules(all),
|
||||
emqx_common_test_helpers:start_apps([]),
|
||||
init_per_testcase(t_too_many_processes_alarm = TestCase, Config) ->
|
||||
Apps = emqx_cth_suite:start(
|
||||
[emqx],
|
||||
#{work_dir => emqx_cth_suite:work_dir(TestCase, Config)}
|
||||
),
|
||||
emqx_config:put([sysmon, vm], #{
|
||||
process_high_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:restart_child(emqx_sys_sup, emqx_vm_mon),
|
||||
Config;
|
||||
init_per_testcase(_, Config) ->
|
||||
emqx_common_test_helpers:boot_modules(all),
|
||||
emqx_common_test_helpers:start_apps([]),
|
||||
Config.
|
||||
[{apps, Apps} | Config];
|
||||
init_per_testcase(TestCase, Config) ->
|
||||
Apps = emqx_cth_suite:start(
|
||||
[emqx],
|
||||
#{work_dir => emqx_cth_suite:work_dir(TestCase, Config)}
|
||||
),
|
||||
[{apps, Apps} | Config].
|
||||
|
||||
end_per_testcase(_, _Config) ->
|
||||
emqx_common_test_helpers:stop_apps([]).
|
||||
end_per_testcase(_, Config) ->
|
||||
Apps = ?config(apps, Config),
|
||||
ok = emqx_cth_suite:stop(Apps),
|
||||
ok.
|
||||
|
||||
t_too_many_processes_alarm(_) ->
|
||||
timer:sleep(500),
|
||||
|
|
|
@ -49,6 +49,10 @@ init_per_testcase(TestCase, Config) when
|
|||
TestCase =/= t_ws_non_check_origin
|
||||
->
|
||||
add_bucket(),
|
||||
Apps = emqx_cth_suite:start(
|
||||
[emqx],
|
||||
#{work_dir => emqx_cth_suite:work_dir(TestCase, Config)}
|
||||
),
|
||||
%% Meck Cm
|
||||
ok = meck:new(emqx_cm, [passthrough, no_history, no_link]),
|
||||
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_recv, fun(_) -> ok end),
|
||||
ok = meck:expect(emqx_metrics, inc_sent, fun(_) -> ok end),
|
||||
PrevConfig = emqx_config:get_listener_conf(ws, default, [websocket]),
|
||||
[
|
||||
{prev_config, PrevConfig}
|
||||
| Config
|
||||
];
|
||||
init_per_testcase(t_ws_non_check_origin, Config) ->
|
||||
[{apps, Apps} | Config];
|
||||
init_per_testcase(t_ws_non_check_origin = TestCase, Config) ->
|
||||
add_bucket(),
|
||||
ok = emqx_common_test_helpers:start_apps([]),
|
||||
PrevConfig = emqx_config:get_listener_conf(ws, default, [websocket]),
|
||||
Apps = emqx_cth_suite:start(
|
||||
[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_origins], []),
|
||||
[
|
||||
{prev_config, PrevConfig}
|
||||
| Config
|
||||
];
|
||||
init_per_testcase(_, Config) ->
|
||||
[{apps, Apps} | Config];
|
||||
init_per_testcase(TestCase, Config) ->
|
||||
add_bucket(),
|
||||
PrevConfig = emqx_config:get_listener_conf(ws, default, [websocket]),
|
||||
ok = emqx_common_test_helpers:start_apps([]),
|
||||
[
|
||||
{prev_config, PrevConfig}
|
||||
| Config
|
||||
].
|
||||
Apps = emqx_cth_suite:start(
|
||||
[emqx],
|
||||
#{work_dir => emqx_cth_suite:work_dir(TestCase, 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,
|
||||
TestCase =/= t_ws_check_origin,
|
||||
TestCase =/= t_ws_non_check_origin,
|
||||
TestCase =/= t_ws_pingreq_before_connected
|
||||
->
|
||||
Apps = ?config(apps, Config),
|
||||
del_bucket(),
|
||||
lists:foreach(
|
||||
fun meck:unload/1,
|
||||
|
@ -122,32 +121,20 @@ end_per_testcase(TestCase, _Config) when
|
|||
emqx_hooks,
|
||||
emqx_metrics
|
||||
]
|
||||
);
|
||||
),
|
||||
ok = emqx_cth_suite:stop(Apps),
|
||||
ok;
|
||||
end_per_testcase(t_ws_non_check_origin, Config) ->
|
||||
Apps = ?config(apps, Config),
|
||||
del_bucket(),
|
||||
PrevConfig = ?config(prev_config, Config),
|
||||
emqx_config:put_listener_conf(ws, default, [websocket], PrevConfig),
|
||||
stop_apps(),
|
||||
ok = emqx_cth_suite:stop(Apps),
|
||||
ok;
|
||||
end_per_testcase(_, Config) ->
|
||||
Apps = ?config(apps, Config),
|
||||
del_bucket(),
|
||||
PrevConfig = ?config(prev_config, Config),
|
||||
emqx_config:put_listener_conf(ws, default, [websocket], PrevConfig),
|
||||
stop_apps(),
|
||||
ok = emqx_cth_suite:stop(Apps),
|
||||
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
|
||||
%%--------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue