Add more test cases (#2992)
* Add more test cases for emqx_stats and emqx_os_mon Fix test case error for emqx_ws_connection * Add more test cases for emqx_sys_mon * Update erlang otp to 22.1 for travis ci * Delete readable=false for make ct * Add unset_all_env for emqx_zone and update test cases
This commit is contained in:
parent
d5412c8d34
commit
c713d619da
|
@ -1,7 +1,7 @@
|
|||
language: erlang
|
||||
|
||||
otp_release:
|
||||
- 21.3
|
||||
- 22.1
|
||||
|
||||
before_install:
|
||||
- git clone https://github.com/erlang/rebar3.git; cd rebar3; ./bootstrap; sudo mv rebar3 /usr/local/bin/; cd ..
|
||||
|
|
2
Makefile
2
Makefile
|
@ -89,7 +89,7 @@ ct_setup:
|
|||
|
||||
.PHONY: ct
|
||||
ct: ct_setup
|
||||
@rebar3 ct -v --readable=false --name $(CT_NODE_NAME) --suite=$(shell echo $(foreach var,$(CT_SUITES),test/$(var)_SUITE) | tr ' ' ',')
|
||||
@rebar3 ct -v --name $(CT_NODE_NAME) --suite=$(shell echo $(foreach var,$(CT_SUITES),test/$(var)_SUITE) | tr ' ' ',')
|
||||
|
||||
## Run one single CT with rebar3
|
||||
## e.g. make ct-one-suite suite=emqx_bridge
|
||||
|
|
|
@ -101,7 +101,7 @@ start_timer(Interval, Msg) ->
|
|||
|
||||
-spec(start_timer(integer(), pid() | atom(), term()) -> reference()).
|
||||
start_timer(Interval, Dest, Msg) ->
|
||||
erlang:start_timer(Interval, Dest, Msg).
|
||||
erlang:start_timer(erlang:ceil(Interval), Dest, Msg).
|
||||
|
||||
-spec(cancel_timer(maybe(reference())) -> ok).
|
||||
cancel_timer(Timer) when is_reference(Timer) ->
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
, get_env/3
|
||||
, set_env/3
|
||||
, unset_env/2
|
||||
, unset_all_env/0
|
||||
]).
|
||||
|
||||
-export([force_reload/0]).
|
||||
|
@ -175,6 +176,11 @@ set_env(Zone, Key, Val) ->
|
|||
unset_env(Zone, Key) ->
|
||||
persistent_term:erase(?KEY(Zone, Key)).
|
||||
|
||||
-spec(unset_all_env() -> ok).
|
||||
unset_all_env() ->
|
||||
[unset_env(Zone, Key) || {?KEY(Zone, Key), _Val} <- persistent_term:get()],
|
||||
ok.
|
||||
|
||||
-spec(force_reload() -> ok).
|
||||
force_reload() ->
|
||||
gen_server:call(?SERVER, force_reload).
|
||||
|
|
|
@ -84,11 +84,44 @@ t_api(_) ->
|
|||
% timer:sleep(2000),
|
||||
% ?assertEqual(true, lists:keymember(cpu_high_watermark, 1, alarm_handler:get_alarms())),
|
||||
|
||||
emqx_os_mon:set_cpu_check_interval(0.05),
|
||||
emqx_os_mon:set_cpu_high_watermark(0.8),
|
||||
emqx_os_mon:set_cpu_low_watermark(0.75),
|
||||
?assertEqual(0.05, emqx_os_mon:get_cpu_check_interval()),
|
||||
?assertEqual(0.8, emqx_os_mon:get_cpu_high_watermark()),
|
||||
?assertEqual(0.75, emqx_os_mon:get_cpu_low_watermark()),
|
||||
% timer:sleep(3000),
|
||||
% ?assertEqual(false, lists:keymember(cpu_high_watermark, 1, alarm_handler:get_alarms())),
|
||||
?assertEqual(ignored, gen_server:call(emqx_os_mon, ignored)),
|
||||
?assertEqual(ok, gen_server:cast(emqx_os_mon, ignored)),
|
||||
emqx_os_mon ! ignored,
|
||||
gen_server:stop(emqx_os_mon),
|
||||
ok.
|
||||
|
||||
t_timeout(_) ->
|
||||
ok = meck:new(emqx_vm),
|
||||
|
||||
ok = meck:expect(emqx_vm, cpu_util, fun() -> 0 end),
|
||||
{ok, _} = emqx_os_mon:start_link([{cpu_check_interval, 1}]),
|
||||
timer:sleep(1500),
|
||||
gen_server:stop(emqx_os_mon),
|
||||
|
||||
ok = meck:expect(emqx_vm, cpu_util, fun() -> {error, test_case} end),
|
||||
{ok, _} = emqx_os_mon:start_link([{cpu_check_interval, 1}]),
|
||||
timer:sleep(1500),
|
||||
gen_server:stop(emqx_os_mon),
|
||||
|
||||
ok = meck:expect(emqx_vm, cpu_util, fun() -> 90 end),
|
||||
{ok, _} = emqx_os_mon:start_link([{cpu_check_interval, 1},
|
||||
{cpu_high_watermark, 0.80},
|
||||
{cpu_low_watermark, 0.60}]),
|
||||
timer:sleep(1500),
|
||||
|
||||
emqx_os_mon:set_cpu_high_watermark(1.00),
|
||||
timer:sleep(1500),
|
||||
|
||||
emqx_os_mon:set_cpu_low_watermark(0.95),
|
||||
timer:sleep(1500),
|
||||
|
||||
gen_server:stop(emqx_os_mon),
|
||||
ok = meck:unload(emqx_vm).
|
||||
|
|
|
@ -23,6 +23,16 @@
|
|||
|
||||
all() -> emqx_ct:all(?MODULE).
|
||||
|
||||
t_cast_useless_msg(_)->
|
||||
emqx_stats:setstat('notExis', 1),
|
||||
with_proc(fun() ->
|
||||
emqx_stats ! useless,
|
||||
?assertEqual(ok, gen_server:cast(emqx_stats, useless))
|
||||
end).
|
||||
|
||||
t_get_error_state(_) ->
|
||||
Conns = emqx_stats:getstats(),
|
||||
?assertEqual([], Conns).
|
||||
|
||||
t_statsfun(_) ->
|
||||
error('TODO').
|
||||
|
@ -38,6 +48,7 @@ t_setstat(_) ->
|
|||
|
||||
t_get_state(_) ->
|
||||
with_proc(fun() ->
|
||||
?assertEqual(undefined, emqx_stats:getstat('notExist')),
|
||||
SetConnsCount = emqx_stats:statsfun('connections.count'),
|
||||
SetConnsCount(1),
|
||||
?assertEqual(1, emqx_stats:getstat('connections.count')),
|
||||
|
@ -69,6 +80,8 @@ t_update_interval(_) ->
|
|||
UpdFun = fun() -> emqx_stats:setstat('connections.count', 1) end,
|
||||
ok = emqx_stats:update_interval(stats_test, UpdFun),
|
||||
timer:sleep(SleepMs),
|
||||
ok = emqx_stats:update_interval(stats_test, UpdFun),
|
||||
timer:sleep(SleepMs),
|
||||
?assertEqual(1, emqx_stats:getstat('connections.count'))
|
||||
end, TickMs).
|
||||
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
concat_str("long_gc warning: pid = ~p, info: ~p", self(), "hello"), "hello"},
|
||||
{self(), long_schedule,
|
||||
concat_str("long_schedule warning: pid = ~p, info: ~p", self(), "hello"), "hello"},
|
||||
{self(), large_heap,
|
||||
concat_str("large_heap warning: pid = ~p, info: ~p", self(), "hello"), "hello"},
|
||||
{self(), busy_port,
|
||||
concat_str("busy_port warning: suspid = ~p, port = ~p",
|
||||
self(), list_to_port("#Port<0.4>")), list_to_port("#Port<0.4>")},
|
||||
|
@ -41,12 +43,35 @@
|
|||
|
||||
all() -> emqx_ct:all(?MODULE).
|
||||
|
||||
init_per_suite(Config) ->
|
||||
init_per_testcase(t_sys_mon, Config) ->
|
||||
emqx_ct_helpers:boot_modules(all),
|
||||
emqx_ct_helpers:start_apps([]),
|
||||
emqx_ct_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),
|
||||
Config;
|
||||
init_per_testcase(t_sys_mon2, Config) ->
|
||||
emqx_ct_helpers:boot_modules(all),
|
||||
emqx_ct_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),
|
||||
Config.
|
||||
|
||||
end_per_suite(_Config) ->
|
||||
end_per_testcase(_, _Config) ->
|
||||
emqx_ct_helpers:stop_apps([]).
|
||||
|
||||
t_sys_mon(_Config) ->
|
||||
|
@ -55,6 +80,13 @@ t_sys_mon(_Config) ->
|
|||
validate_sys_mon_info(PidOrPort, SysMonName,ValidateInfo, InfoOrPort)
|
||||
end, ?INPUTINFO).
|
||||
|
||||
t_sys_mon2(_Config) ->
|
||||
?SYSMON ! {timeout, ignored, reset},
|
||||
?SYSMON ! {ignored},
|
||||
?assertEqual(ignored, gen_server:call(?SYSMON, ignored)),
|
||||
?assertEqual(ok, gen_server:cast(?SYSMON, ignored)),
|
||||
gen_server:stop(?SYSMON).
|
||||
|
||||
validate_sys_mon_info(PidOrPort, SysMonName,ValidateInfo, InfoOrPort) ->
|
||||
{ok, C} = emqtt:start_link([{host, "localhost"}]),
|
||||
{ok, _} = emqtt:connect(C),
|
||||
|
|
|
@ -106,7 +106,7 @@ t_websocket_init(_) ->
|
|||
|
||||
t_websocket_handle_binary(_) ->
|
||||
with_ws_conn(fun(WsConn) ->
|
||||
ok = meck:expect(emqx_channel, recvd, fun(_Oct, Channel) -> {ok, Channel} end),
|
||||
ok = meck:expect(emqx_channel, recvd, fun(_Oct, Channel) -> Channel end),
|
||||
{ok, WsConn} = websocket_handle({binary, [<<>>]}, WsConn)
|
||||
end).
|
||||
|
||||
|
|
|
@ -56,6 +56,7 @@ init_per_suite(Config) ->
|
|||
Config.
|
||||
|
||||
end_per_suite(_Config) ->
|
||||
emqx_zone:unset_all_env(),
|
||||
application:unset_env(emqx, zone_env),
|
||||
application:unset_env(emqx, zones).
|
||||
|
||||
|
|
Loading…
Reference in New Issue