test: fix flaky tests
This commit is contained in:
parent
6dd66753bb
commit
0925f2104c
|
@ -94,15 +94,15 @@ end_per_testcase(Case, Config) when
|
||||||
->
|
->
|
||||||
PrevListener = ?config(prev_listener_conf, Config),
|
PrevListener = ?config(prev_listener_conf, Config),
|
||||||
PrevRateLimit = ?config(prev_rate_limit_conf, Config),
|
PrevRateLimit = ?config(prev_rate_limit_conf, Config),
|
||||||
|
emqx_listeners:stop(),
|
||||||
emqx_config:put([listeners, tcp], PrevListener),
|
emqx_config:put([listeners, tcp], PrevListener),
|
||||||
emqx_config:put([rate_limit], PrevRateLimit),
|
emqx_config:put([rate_limit], PrevRateLimit),
|
||||||
emqx_listeners:stop(),
|
|
||||||
_ = emqx_config_handler:stop(),
|
_ = emqx_config_handler:stop(),
|
||||||
ok;
|
ok;
|
||||||
end_per_testcase(t_wss_conn, Config) ->
|
end_per_testcase(t_wss_conn, Config) ->
|
||||||
PrevListener = ?config(prev_listener_conf, Config),
|
PrevListener = ?config(prev_listener_conf, Config),
|
||||||
emqx_config:put([listeners, wss], PrevListener),
|
|
||||||
emqx_listeners:stop(),
|
emqx_listeners:stop(),
|
||||||
|
emqx_config:put([listeners, wss], PrevListener),
|
||||||
_ = emqx_config_handler:stop(),
|
_ = emqx_config_handler:stop(),
|
||||||
ok;
|
ok;
|
||||||
end_per_testcase(_, _Config) ->
|
end_per_testcase(_, _Config) ->
|
||||||
|
|
|
@ -21,17 +21,27 @@
|
||||||
|
|
||||||
-include_lib("emqx/include/emqx.hrl").
|
-include_lib("emqx/include/emqx.hrl").
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
-include_lib("common_test/include/ct.hrl").
|
||||||
|
|
||||||
-define(R, emqx_router).
|
-define(R, emqx_router).
|
||||||
|
|
||||||
all() -> emqx_common_test_helpers:all(?MODULE).
|
all() -> emqx_common_test_helpers:all(?MODULE).
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
|
PrevBootModules = application:get_env(emqx, boot_modules),
|
||||||
emqx_common_test_helpers:boot_modules([router]),
|
emqx_common_test_helpers:boot_modules([router]),
|
||||||
emqx_common_test_helpers:start_apps([]),
|
emqx_common_test_helpers:start_apps([]),
|
||||||
Config.
|
[
|
||||||
|
{prev_boot_modules, PrevBootModules}
|
||||||
|
| Config
|
||||||
|
].
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(Config) ->
|
||||||
|
PrevBootModules = ?config(prev_boot_modules, Config),
|
||||||
|
case PrevBootModules of
|
||||||
|
undefined -> ok;
|
||||||
|
{ok, Mods} -> emqx_common_test_helpers:boot_modules(Mods)
|
||||||
|
end,
|
||||||
emqx_common_test_helpers:stop_apps([]).
|
emqx_common_test_helpers:stop_apps([]).
|
||||||
|
|
||||||
init_per_testcase(_TestCase, Config) ->
|
init_per_testcase(_TestCase, Config) ->
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
-include_lib("emqx/include/emqx.hrl").
|
-include_lib("emqx/include/emqx.hrl").
|
||||||
-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").
|
||||||
|
|
||||||
-compile(export_all).
|
-compile(export_all).
|
||||||
-compile(nowarn_export_all).
|
-compile(nowarn_export_all).
|
||||||
|
@ -89,10 +90,27 @@ 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),
|
||||||
Config;
|
PrevConfig = emqx_config:get_listener_conf(ws, default, [websocket]),
|
||||||
init_per_testcase(_, Config) ->
|
[
|
||||||
|
{prev_config, PrevConfig}
|
||||||
|
| Config
|
||||||
|
];
|
||||||
|
init_per_testcase(t_ws_non_check_origin, Config) ->
|
||||||
ok = emqx_common_test_helpers:start_apps([]),
|
ok = emqx_common_test_helpers:start_apps([]),
|
||||||
Config.
|
PrevConfig = emqx_config:get_listener_conf(ws, default, [websocket]),
|
||||||
|
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) ->
|
||||||
|
PrevConfig = emqx_config:get_listener_conf(ws, default, [websocket]),
|
||||||
|
ok = emqx_common_test_helpers:start_apps([]),
|
||||||
|
[
|
||||||
|
{prev_config, PrevConfig}
|
||||||
|
| 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,
|
||||||
|
@ -112,7 +130,14 @@ end_per_testcase(TestCase, _Config) when
|
||||||
emqx_metrics
|
emqx_metrics
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
end_per_testcase(t_ws_non_check_origin, Config) ->
|
||||||
|
PrevConfig = ?config(prev_config, Config),
|
||||||
|
emqx_config:put_listener_conf(ws, default, [websocket], PrevConfig),
|
||||||
|
emqx_common_test_helpers:stop_apps([]),
|
||||||
|
ok;
|
||||||
end_per_testcase(_, Config) ->
|
end_per_testcase(_, Config) ->
|
||||||
|
PrevConfig = ?config(prev_config, Config),
|
||||||
|
emqx_config:put_listener_conf(ws, default, [websocket], PrevConfig),
|
||||||
emqx_common_test_helpers:stop_apps([]),
|
emqx_common_test_helpers:stop_apps([]),
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
|
@ -314,8 +339,6 @@ t_ws_check_origin(_) ->
|
||||||
).
|
).
|
||||||
|
|
||||||
t_ws_non_check_origin(_) ->
|
t_ws_non_check_origin(_) ->
|
||||||
emqx_config:put_listener_conf(ws, default, [websocket, check_origin_enable], false),
|
|
||||||
emqx_config:put_listener_conf(ws, default, [websocket, check_origins], []),
|
|
||||||
{ok, _} = application:ensure_all_started(gun),
|
{ok, _} = application:ensure_all_started(gun),
|
||||||
?assertMatch(
|
?assertMatch(
|
||||||
{gun_upgrade, _},
|
{gun_upgrade, _},
|
||||||
|
|
|
@ -54,6 +54,8 @@ end_per_testcase(t_get_basic_usage_info_2, _Config) ->
|
||||||
emqx_gateway_cm:unregister_channel(lwm2m, <<"client_id">>),
|
emqx_gateway_cm:unregister_channel(lwm2m, <<"client_id">>),
|
||||||
emqx_config:put([gateway], #{}),
|
emqx_config:put([gateway], #{}),
|
||||||
emqx_common_test_helpers:stop_apps([emqx_gateway]),
|
emqx_common_test_helpers:stop_apps([emqx_gateway]),
|
||||||
|
emqx_config:erase(gateway),
|
||||||
|
emqx_common_test_helpers:load_config(emqx_gateway_schema, ?CONF_DEFAULT),
|
||||||
emqx_common_test_helpers:start_apps([emqx_gateway]),
|
emqx_common_test_helpers:start_apps([emqx_gateway]),
|
||||||
ok;
|
ok;
|
||||||
end_per_testcase(_TestCase, _Config) ->
|
end_per_testcase(_TestCase, _Config) ->
|
||||||
|
|
Loading…
Reference in New Issue