fix(test): update the testcases for emqx_os_mon_SUITE
This commit is contained in:
parent
01c4c655fb
commit
3aaf7041a6
|
@ -24,13 +24,7 @@
|
|||
|
||||
-export([start_link/0]).
|
||||
|
||||
-export([ get_cpu_check_interval/0
|
||||
, set_cpu_check_interval/1
|
||||
, get_cpu_high_watermark/0
|
||||
, set_cpu_high_watermark/1
|
||||
, get_cpu_low_watermark/0
|
||||
, set_cpu_low_watermark/1
|
||||
, get_mem_check_interval/0
|
||||
-export([ get_mem_check_interval/0
|
||||
, set_mem_check_interval/1
|
||||
, get_sysmem_high_watermark/0
|
||||
, set_sysmem_high_watermark/1
|
||||
|
@ -58,24 +52,6 @@ start_link() ->
|
|||
%% API
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
get_cpu_check_interval() ->
|
||||
call(get_cpu_check_interval).
|
||||
|
||||
set_cpu_check_interval(Seconds) ->
|
||||
call({set_cpu_check_interval, Seconds}).
|
||||
|
||||
get_cpu_high_watermark() ->
|
||||
call(get_cpu_high_watermark).
|
||||
|
||||
set_cpu_high_watermark(Float) ->
|
||||
call({set_cpu_high_watermark, Float}).
|
||||
|
||||
get_cpu_low_watermark() ->
|
||||
call(get_cpu_low_watermark).
|
||||
|
||||
set_cpu_low_watermark(Float) ->
|
||||
call({set_cpu_low_watermark, Float}).
|
||||
|
||||
get_mem_check_interval() ->
|
||||
memsup:get_check_interval() div 1000.
|
||||
|
||||
|
@ -96,9 +72,6 @@ get_procmem_high_watermark() ->
|
|||
set_procmem_high_watermark(Float) ->
|
||||
memsup:set_procmem_high_watermark(Float).
|
||||
|
||||
call(Req) ->
|
||||
gen_server:call(?OS_MON, Req, infinity).
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% gen_server callbacks
|
||||
%%--------------------------------------------------------------------
|
||||
|
@ -111,24 +84,6 @@ init([]) ->
|
|||
start_check_timer(),
|
||||
{ok, #{}}.
|
||||
|
||||
handle_call(get_cpu_check_interval, _From, State) ->
|
||||
{reply, maps:get(cpu_check_interval, State, undefined), State};
|
||||
|
||||
handle_call({set_cpu_check_interval, Seconds}, _From, State) ->
|
||||
{reply, ok, State#{cpu_check_interval := Seconds}};
|
||||
|
||||
handle_call(get_cpu_high_watermark, _From, State) ->
|
||||
{reply, maps:get(cpu_high_watermark, State, undefined), State};
|
||||
|
||||
handle_call({set_cpu_high_watermark, Float}, _From, State) ->
|
||||
{reply, ok, State#{cpu_high_watermark := Float}};
|
||||
|
||||
handle_call(get_cpu_low_watermark, _From, State) ->
|
||||
{reply, maps:get(cpu_low_watermark, State, undefined), State};
|
||||
|
||||
handle_call({set_cpu_low_watermark, Float}, _From, State) ->
|
||||
{reply, ok, State#{cpu_low_watermark := Float}};
|
||||
|
||||
handle_call(Req, _From, State) ->
|
||||
?LOG(error, "Unexpected call: ~p", [Req]),
|
||||
{reply, ignored, State}.
|
||||
|
|
|
@ -24,46 +24,34 @@
|
|||
all() -> emqx_ct:all(?MODULE).
|
||||
|
||||
init_per_suite(Config) ->
|
||||
emqx_config:put([sysmon, os], #{
|
||||
cpu_check_interval => 60,cpu_high_watermark => 0.8,
|
||||
cpu_low_watermark => 0.6,mem_check_interval => 60,
|
||||
procmem_high_watermark => 0.05,sysmem_high_watermark => 0.7}),
|
||||
application:ensure_all_started(os_mon),
|
||||
Config.
|
||||
|
||||
end_per_suite(_Config) ->
|
||||
application:stop(os_mon).
|
||||
|
||||
% t_set_mem_check_interval(_) ->
|
||||
% error('TODO').
|
||||
|
||||
% t_set_sysmem_high_watermark(_) ->
|
||||
% error('TODO').
|
||||
|
||||
% t_set_procmem_high_watermark(_) ->
|
||||
% error('TODO').
|
||||
|
||||
t_api(_) ->
|
||||
gen_event:swap_handler(alarm_handler, {emqx_alarm_handler, swap}, {alarm_handler, []}),
|
||||
{ok, _} = emqx_os_mon:start_link([{cpu_check_interval, 1},
|
||||
{cpu_high_watermark, 5},
|
||||
{cpu_low_watermark, 80},
|
||||
{mem_check_interval, 60},
|
||||
{sysmem_high_watermark, 70},
|
||||
{procmem_high_watermark, 5}]),
|
||||
?assertEqual(1, emqx_os_mon:get_cpu_check_interval()),
|
||||
?assertEqual(5, emqx_os_mon:get_cpu_high_watermark()),
|
||||
?assertEqual(80, emqx_os_mon:get_cpu_low_watermark()),
|
||||
?assertEqual(60, emqx_os_mon:get_mem_check_interval()),
|
||||
?assertEqual(70, emqx_os_mon:get_sysmem_high_watermark()),
|
||||
?assertEqual(5, emqx_os_mon:get_procmem_high_watermark()),
|
||||
% timer:sleep(2000),
|
||||
% ?assertEqual(true, lists:keymember(cpu_high_watermark, 1, alarm_handler:get_alarms())),
|
||||
{ok, _} = emqx_os_mon:start_link(),
|
||||
|
||||
?assertEqual(60, emqx_os_mon:get_mem_check_interval()),
|
||||
?assertEqual(ok, emqx_os_mon:set_mem_check_interval(30)),
|
||||
?assertEqual(60, emqx_os_mon:get_mem_check_interval()),
|
||||
?assertEqual(ok, emqx_os_mon:set_mem_check_interval(122)),
|
||||
?assertEqual(120, emqx_os_mon:get_mem_check_interval()),
|
||||
|
||||
?assertEqual(70, emqx_os_mon:get_sysmem_high_watermark()),
|
||||
?assertEqual(ok, emqx_os_mon:set_sysmem_high_watermark(0.8)),
|
||||
?assertEqual(80, emqx_os_mon:get_sysmem_high_watermark()),
|
||||
|
||||
?assertEqual(5, emqx_os_mon:get_procmem_high_watermark()),
|
||||
?assertEqual(ok, emqx_os_mon:set_procmem_high_watermark(0.11)),
|
||||
?assertEqual(11, emqx_os_mon:get_procmem_high_watermark()),
|
||||
|
||||
emqx_os_mon:set_cpu_check_interval(0.05),
|
||||
emqx_os_mon:set_cpu_high_watermark(80),
|
||||
emqx_os_mon:set_cpu_low_watermark(75),
|
||||
?assertEqual(0.05, emqx_os_mon:get_cpu_check_interval()),
|
||||
?assertEqual(80, emqx_os_mon:get_cpu_high_watermark()),
|
||||
?assertEqual(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,
|
||||
|
|
Loading…
Reference in New Issue