test: add more tests to telemetry

This commit is contained in:
Thales Macedo Garitezi 2022-03-22 15:28:42 -03:00
parent 35a523230f
commit fbfbaa8a9a
No known key found for this signature in database
GPG Key ID: DD279F8152A9B6DD
1 changed files with 30 additions and 2 deletions

View File

@ -69,7 +69,9 @@ init_per_testcase(t_get_telemetry, Config) ->
init_per_testcase(_Testcase, Config) -> init_per_testcase(_Testcase, Config) ->
TestPID = self(), TestPID = self(),
ok = meck:new(httpc, [non_strict, passthrough, no_history, no_link]), ok = meck:new(httpc, [non_strict, passthrough, no_history, no_link]),
ok = meck:expect(httpc, request, fun(Method, URL, Headers, Body) -> ok = meck:expect(httpc, request, fun(
Method, {URL, Headers, _ContentType, Body}, _HTTPOpts, _Opts
) ->
TestPID ! {request, Method, URL, Headers, Body} TestPID ! {request, Method, URL, Headers, Body}
end), end),
Config. Config.
@ -154,7 +156,33 @@ t_send_after_enable(_) ->
ok = snabbkaffe:start_trace(), ok = snabbkaffe:start_trace(),
try try
ok = emqx_telemetry:enable(), ok = emqx_telemetry:enable(),
?assertMatch({ok, _}, ?block_until(#{?snk_kind := telemetry_data_reported}, 2000, 100)) ?assertMatch({ok, _}, ?block_until(#{?snk_kind := telemetry_data_reported}, 2000, 100)),
receive
{request, post, _URL, _Headers, Body} ->
{ok, Decoded} = emqx_json:safe_decode(Body, [return_maps]),
?assertMatch(
#{
<<"uuid">> := _,
<<"messages_received">> := _,
<<"messages_sent">> := _,
<<"build_info">> := #{},
<<"vm_specs">> :=
#{
<<"num_cpus">> := _,
<<"total_memory">> := _
},
<<"mqtt_runtime_insights">> :=
#{
<<"messages_received_rate">> := _,
<<"messages_sent_rate">> := _,
<<"num_topics">> := _
}
},
Decoded
)
after 2100 ->
exit(telemetry_not_reported)
end
after after
ok = snabbkaffe:stop(), ok = snabbkaffe:stop(),
meck:unload([emqx_telemetry]) meck:unload([emqx_telemetry])