fix(test): update the testcases for emqx_vm_mon_SUITE
This commit is contained in:
parent
400e08e229
commit
6d9918d3e5
|
@ -60,9 +60,10 @@ handle_info({timeout, _Timer, check}, State) ->
|
||||||
ProcHighWatermark = emqx_config:get([sysmon, vm, process_high_watermark]),
|
ProcHighWatermark = emqx_config:get([sysmon, vm, process_high_watermark]),
|
||||||
ProcLowWatermark = emqx_config:get([sysmon, vm, process_low_watermark]),
|
ProcLowWatermark = emqx_config:get([sysmon, vm, process_low_watermark]),
|
||||||
ProcessCount = erlang:system_info(process_count),
|
ProcessCount = erlang:system_info(process_count),
|
||||||
case ProcessCount / erlang:system_info(process_limit) * 100 of
|
case ProcessCount / erlang:system_info(process_limit) of
|
||||||
Percent when Percent >= ProcHighWatermark ->
|
Percent when Percent >= ProcHighWatermark ->
|
||||||
emqx_alarm:activate(too_many_processes, #{usage => Percent,
|
emqx_alarm:activate(too_many_processes, #{
|
||||||
|
usage => io_lib:format("~p%", [Percent*100]),
|
||||||
high_watermark => ProcHighWatermark,
|
high_watermark => ProcHighWatermark,
|
||||||
low_watermark => ProcLowWatermark});
|
low_watermark => ProcLowWatermark});
|
||||||
Percent when Percent < ProcLowWatermark ->
|
Percent when Percent < ProcLowWatermark ->
|
||||||
|
@ -89,4 +90,4 @@ code_change(_OldVsn, State, _Extra) ->
|
||||||
|
|
||||||
start_check_timer() ->
|
start_check_timer() ->
|
||||||
Interval = emqx_config:get([sysmon, vm, process_check_interval]),
|
Interval = emqx_config:get([sysmon, vm, process_check_interval]),
|
||||||
emqx_misc:start_timer(timer:seconds(Interval), check).
|
emqx_misc:start_timer(Interval, check).
|
||||||
|
|
|
@ -23,17 +23,16 @@
|
||||||
|
|
||||||
all() -> emqx_ct:all(?MODULE).
|
all() -> emqx_ct:all(?MODULE).
|
||||||
|
|
||||||
init_per_testcase(t_api, Config) ->
|
init_per_testcase(t_alarms, Config) ->
|
||||||
emqx_ct_helpers:boot_modules(all),
|
emqx_ct_helpers:boot_modules(all),
|
||||||
emqx_ct_helpers:start_apps([],
|
emqx_ct_helpers:start_apps([]),
|
||||||
fun(emqx) ->
|
emqx_config:put([sysmon, vm], #{
|
||||||
application:set_env(emqx, vm_mon, [{check_interval, 1},
|
process_high_watermark => 0,
|
||||||
{process_high_watermark, 80},
|
process_low_watermark => 0,
|
||||||
{process_low_watermark, 75}]),
|
process_check_interval => 100 %% 1s
|
||||||
ok;
|
}),
|
||||||
(_) ->
|
ok = supervisor:terminate_child(emqx_sys_sup, emqx_vm_mon),
|
||||||
ok
|
{ok, _} = supervisor:restart_child(emqx_sys_sup, emqx_vm_mon),
|
||||||
end),
|
|
||||||
Config;
|
Config;
|
||||||
init_per_testcase(_, Config) ->
|
init_per_testcase(_, Config) ->
|
||||||
emqx_ct_helpers:boot_modules(all),
|
emqx_ct_helpers:boot_modules(all),
|
||||||
|
@ -43,18 +42,12 @@ init_per_testcase(_, Config) ->
|
||||||
end_per_testcase(_, _Config) ->
|
end_per_testcase(_, _Config) ->
|
||||||
emqx_ct_helpers:stop_apps([]).
|
emqx_ct_helpers:stop_apps([]).
|
||||||
|
|
||||||
t_api(_) ->
|
t_alarms(_) ->
|
||||||
?assertEqual(1, emqx_vm_mon:get_check_interval()),
|
timer:sleep(500),
|
||||||
?assertEqual(80, emqx_vm_mon:get_process_high_watermark()),
|
|
||||||
?assertEqual(75, emqx_vm_mon:get_process_low_watermark()),
|
|
||||||
emqx_vm_mon:set_process_high_watermark(0),
|
|
||||||
emqx_vm_mon:set_process_low_watermark(60),
|
|
||||||
?assertEqual(0, emqx_vm_mon:get_process_high_watermark()),
|
|
||||||
?assertEqual(60, emqx_vm_mon:get_process_low_watermark()),
|
|
||||||
timer:sleep(emqx_vm_mon:get_check_interval() * 1000 * 2),
|
|
||||||
?assert(is_existing(too_many_processes, emqx_alarm:get_alarms(activated))),
|
?assert(is_existing(too_many_processes, emqx_alarm:get_alarms(activated))),
|
||||||
emqx_vm_mon:set_process_high_watermark(70),
|
emqx_config:put([sysmon, vm, process_high_watermark], 70),
|
||||||
timer:sleep(emqx_vm_mon:get_check_interval() * 1000 * 2),
|
emqx_config:put([sysmon, vm, process_low_watermark], 60),
|
||||||
|
timer:sleep(500),
|
||||||
?assertNot(is_existing(too_many_processes, emqx_alarm:get_alarms(activated))).
|
?assertNot(is_existing(too_many_processes, emqx_alarm:get_alarms(activated))).
|
||||||
|
|
||||||
is_existing(Name, [#{name := Name} | _More]) ->
|
is_existing(Name, [#{name := Name} | _More]) ->
|
||||||
|
|
Loading…
Reference in New Issue