|
|
@@ -39,29 +39,47 @@ init_per_testcase(t_cpu_check_alarm, Config) ->
|
|
|
%% 200ms
|
|
|
cpu_check_interval => 200
|
|
|
}),
|
|
|
- ok = supervisor:terminate_child(emqx_sys_sup, emqx_os_mon),
|
|
|
- {ok, _} = supervisor:restart_child(emqx_sys_sup, emqx_os_mon),
|
|
|
+ restart_os_mon(),
|
|
|
Config;
|
|
|
init_per_testcase(t_sys_mem_check_alarm, Config) ->
|
|
|
- case emqx_os_mon:is_sysmem_check_supported() of
|
|
|
+ case emqx_os_mon:is_os_check_supported() of
|
|
|
true ->
|
|
|
SysMon = emqx_config:get([sysmon, os], #{}),
|
|
|
emqx_config:put([sysmon, os], SysMon#{
|
|
|
sysmem_high_watermark => 0.51,
|
|
|
%% 200ms
|
|
|
mem_check_interval => 200
|
|
|
- }),
|
|
|
- ok = supervisor:terminate_child(emqx_sys_sup, emqx_os_mon),
|
|
|
- {ok, _} = supervisor:restart_child(emqx_sys_sup, emqx_os_mon),
|
|
|
- Config;
|
|
|
+ });
|
|
|
false ->
|
|
|
- Config
|
|
|
- end;
|
|
|
+ ok
|
|
|
+ end,
|
|
|
+ restart_os_mon(),
|
|
|
+ Config;
|
|
|
init_per_testcase(_, Config) ->
|
|
|
- emqx_common_test_helpers:boot_modules(all),
|
|
|
- emqx_common_test_helpers:start_apps([]),
|
|
|
+ restart_os_mon(),
|
|
|
Config.
|
|
|
|
|
|
+restart_os_mon() ->
|
|
|
+ case emqx_os_mon:is_os_check_supported() of
|
|
|
+ true ->
|
|
|
+ ok = supervisor:terminate_child(emqx_sys_sup, emqx_os_mon),
|
|
|
+ {ok, _} = supervisor:restart_child(emqx_sys_sup, emqx_os_mon);
|
|
|
+ false ->
|
|
|
+ _ = supervisor:terminate_child(emqx_sys_sup, emqx_os_mon),
|
|
|
+ _ = supervisor:delete_child(emqx_sys_sup, emqx_os_mon),
|
|
|
+ %% run test on mac/windows.
|
|
|
+ Mod = emqx_os_mon,
|
|
|
+ OsMon = #{
|
|
|
+ id => Mod,
|
|
|
+ start => {Mod, start_link, []},
|
|
|
+ restart => permanent,
|
|
|
+ shutdown => 5000,
|
|
|
+ type => worker,
|
|
|
+ modules => [Mod]
|
|
|
+ },
|
|
|
+ {ok, _} = supervisor:start_child(emqx_sys_sup, OsMon)
|
|
|
+ end.
|
|
|
+
|
|
|
t_api(_) ->
|
|
|
?assertEqual(0.7, emqx_os_mon:get_sysmem_high_watermark()),
|
|
|
?assertEqual(ok, emqx_os_mon:set_sysmem_high_watermark(0.8)),
|
|
|
@@ -81,7 +99,7 @@ t_api(_) ->
|
|
|
ok.
|
|
|
|
|
|
t_sys_mem_check_disable(Config) ->
|
|
|
- case emqx_os_mon:is_sysmem_check_supported() of
|
|
|
+ case emqx_os_mon:is_os_check_supported() of
|
|
|
true -> do_sys_mem_check_disable(Config);
|
|
|
false -> skip
|
|
|
end.
|
|
|
@@ -100,7 +118,7 @@ do_sys_mem_check_disable(_Config) ->
|
|
|
ok.
|
|
|
|
|
|
t_sys_mem_check_alarm(Config) ->
|
|
|
- case emqx_os_mon:is_sysmem_check_supported() of
|
|
|
+ case emqx_os_mon:is_os_check_supported() of
|
|
|
true -> do_sys_mem_check_alarm(Config);
|
|
|
false -> skip
|
|
|
end.
|
|
|
@@ -167,7 +185,7 @@ t_cpu_check_alarm(_) ->
|
|
|
util,
|
|
|
fun() -> CpuUtil end,
|
|
|
fun() ->
|
|
|
- timer:sleep(500),
|
|
|
+ timer:sleep(1000),
|
|
|
Alarms = emqx_alarm:get_alarms(activated),
|
|
|
?assert(
|
|
|
emqx_vm_mon_SUITE:is_existing(high_cpu_usage, emqx_alarm:get_alarms(activated))
|
|
|
@@ -193,7 +211,7 @@ t_cpu_check_alarm(_) ->
|
|
|
?assert(is_binary(Msg)),
|
|
|
emqx_config:put([sysmon, os, cpu_high_watermark], 1),
|
|
|
emqx_config:put([sysmon, os, cpu_low_watermark], 0.96),
|
|
|
- timer:sleep(500),
|
|
|
+ timer:sleep(800),
|
|
|
?assertNot(
|
|
|
emqx_vm_mon_SUITE:is_existing(high_cpu_usage, emqx_alarm:get_alarms(activated))
|
|
|
)
|