test: cpu_sup:load mock test

This commit is contained in:
Zhongwen Deng 2023-01-29 11:01:43 +08:00
parent 2d67bb3fb6
commit 5783127c30
3 changed files with 19 additions and 4 deletions

View File

@ -233,9 +233,7 @@ mem_info() ->
[{total_memory, Total}, {used_memory, Total - Free}].
ftos(F) when is_float(F) ->
float_to_binary(F, [{decimals, 2}]);
ftos(F) when is_integer(F) ->
ftos(F / 1.0).
float_to_binary(F, [{decimals, 2}]).
%%%% erlang vm scheduler_usage fun copied from recon
scheduler_usage(Interval) when is_integer(Interval) ->

View File

@ -24,7 +24,21 @@
all() -> emqx_common_test_helpers:all(?MODULE).
t_load(_Config) ->
?assertMatch([{load1, _}, {load5, _}, {load15, _}], emqx_vm:loads()).
lists:foreach(
fun(Avg, Int) ->
emqx_common_test_helpers:with_mock(
cpu_sup,
Avg,
fun() -> Int end,
fun() ->
Load = proplists:get_value(Avg, emqx_vm:loads()),
?assertEqual(Int / 1.0, Load)
end
),
?assertMatch([{load1, _}, {load5, _}, {load15, _}], emqx_vm:loads())
end,
[{load1, 1}, {load5, 5}, {load15, 15}]
).
t_systeminfo(_Config) ->
?assertEqual(

View File

@ -40,6 +40,9 @@ t_alarms_api(_) ->
get_alarms(1, true),
get_alarms(1, false).
t_alarm_cpu(_) ->
ok.
t_delete_alarms_api(_) ->
Path = emqx_mgmt_api_test_util:api_path(["alarms"]),
{ok, _} = emqx_mgmt_api_test_util:request_api(delete, Path),