test(trace): split test case
This commit is contained in:
parent
3547dc4c93
commit
c81df7278f
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
-include_lib("common_test/include/ct.hrl").
|
-include_lib("common_test/include/ct.hrl").
|
||||||
|
|
||||||
all() -> [t_start_traces].
|
all() -> [t_trace_clientid, t_trace_topic].
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
emqx_ct_helpers:boot_modules(all),
|
emqx_ct_helpers:boot_modules(all),
|
||||||
|
@ -33,7 +33,7 @@ init_per_suite(Config) ->
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(_Config) ->
|
||||||
emqx_ct_helpers:stop_apps([]).
|
emqx_ct_helpers:stop_apps([]).
|
||||||
|
|
||||||
t_start_traces(_Config) ->
|
t_trace_clientid(_Config) ->
|
||||||
{ok, T} = emqtt:start_link([{host, "localhost"},
|
{ok, T} = emqtt:start_link([{host, "localhost"},
|
||||||
{clientid, <<"client">>},
|
{clientid, <<"client">>},
|
||||||
{username, <<"testuser">>},
|
{username, <<"testuser">>},
|
||||||
|
@ -50,21 +50,17 @@ t_start_traces(_Config) ->
|
||||||
ok = emqx_tracer:start_trace({clientid, <<"client3">>}, all, "tmp/client3.log"),
|
ok = emqx_tracer:start_trace({clientid, <<"client3">>}, all, "tmp/client3.log"),
|
||||||
{error, {invalid_log_level, bad_level}} = emqx_tracer:start_trace({clientid, <<"client4">>}, bad_level, "tmp/client4.log"),
|
{error, {invalid_log_level, bad_level}} = emqx_tracer:start_trace({clientid, <<"client4">>}, bad_level, "tmp/client4.log"),
|
||||||
{error, {handler_not_added, {file_error,".",eisdir}}} = emqx_tracer:start_trace({clientid, <<"client5">>}, debug, "."),
|
{error, {handler_not_added, {file_error,".",eisdir}}} = emqx_tracer:start_trace({clientid, <<"client5">>}, debug, "."),
|
||||||
ok = emqx_tracer:start_trace({topic, <<"a/#">>}, all, "tmp/topic_trace.log"),
|
|
||||||
ok = emqx_tracer:start_trace({topic, <<"b/#">>}, all, "tmp/topic_trace.log"),
|
|
||||||
ct:sleep(100),
|
ct:sleep(100),
|
||||||
|
|
||||||
%% Verify the tracing file exits
|
%% Verify the tracing file exits
|
||||||
?assert(filelib:is_regular("tmp/client.log")),
|
?assert(filelib:is_regular("tmp/client.log")),
|
||||||
?assert(filelib:is_regular("tmp/client2.log")),
|
?assert(filelib:is_regular("tmp/client2.log")),
|
||||||
?assert(filelib:is_regular("tmp/topic_trace.log")),
|
|
||||||
|
|
||||||
%% Get current traces
|
%% Get current traces
|
||||||
?assertEqual([{{clientid,"client"},{debug,"tmp/client.log"}},
|
?assertEqual([{{clientid,"client"},{debug,"tmp/client.log"}},
|
||||||
{{clientid,"client2"},{debug,"tmp/client2.log"}},
|
{{clientid,"client2"},{debug,"tmp/client2.log"}},
|
||||||
{{clientid,"client3"},{debug,"tmp/client3.log"}},
|
{{clientid,"client3"},{debug,"tmp/client3.log"}}
|
||||||
{{topic,"a/#"},{debug,"tmp/topic_trace.log"}},
|
], emqx_tracer:lookup_traces()),
|
||||||
{{topic,"b/#"},{debug,"tmp/topic_trace.log"}}], emqx_tracer:lookup_traces()),
|
|
||||||
|
|
||||||
%% set the overall log level to debug
|
%% set the overall log level to debug
|
||||||
emqx_logger:set_log_level(debug),
|
emqx_logger:set_log_level(debug),
|
||||||
|
@ -73,19 +69,52 @@ t_start_traces(_Config) ->
|
||||||
emqtt:publish(T, <<"a/b/c">>, <<"hi">>),
|
emqtt:publish(T, <<"a/b/c">>, <<"hi">>),
|
||||||
ct:sleep(200),
|
ct:sleep(200),
|
||||||
|
|
||||||
%% Verify messages are logged to "tmp/client.log" and "tmp/topic_trace.log", but not "tmp/client2.log".
|
%% Verify messages are logged to "tmp/client.log" but not "tmp/client2.log".
|
||||||
?assert(filelib:file_size("tmp/client.log") > 0),
|
?assert(filelib:file_size("tmp/client.log") > 0),
|
||||||
?assert(filelib:file_size("tmp/topic_trace.log") > 0),
|
|
||||||
?assert(filelib:file_size("tmp/client2.log") == 0),
|
?assert(filelib:file_size("tmp/client2.log") == 0),
|
||||||
|
|
||||||
%% Stop tracing
|
%% Stop tracing
|
||||||
ok = emqx_tracer:stop_trace({clientid, <<"client">>}),
|
ok = emqx_tracer:stop_trace({clientid, <<"client">>}),
|
||||||
ok = emqx_tracer:stop_trace({clientid, <<"client2">>}),
|
ok = emqx_tracer:stop_trace({clientid, <<"client2">>}),
|
||||||
ok = emqx_tracer:stop_trace({clientid, <<"client3">>}),
|
ok = emqx_tracer:stop_trace({clientid, <<"client3">>}),
|
||||||
ok = emqx_tracer:stop_trace({topic, <<"a/#">>}),
|
|
||||||
ok = emqx_tracer:stop_trace({topic, <<"b/#">>}),
|
|
||||||
{error, _Reason} = emqx_tracer:stop_trace({topic, <<"c/#">>}),
|
|
||||||
emqtt:disconnect(T),
|
emqtt:disconnect(T),
|
||||||
|
|
||||||
emqx_logger:set_log_level(warning).
|
emqx_logger:set_log_level(warning).
|
||||||
|
|
||||||
|
t_trace_topic(_Config) ->
|
||||||
|
{ok, T} = emqtt:start_link([{host, "localhost"},
|
||||||
|
{clientid, <<"client">>},
|
||||||
|
{username, <<"testuser">>},
|
||||||
|
{password, <<"pass">>}
|
||||||
|
]),
|
||||||
|
emqtt:connect(T),
|
||||||
|
|
||||||
|
%% Start tracing
|
||||||
|
emqx_logger:set_log_level(debug),
|
||||||
|
ok = emqx_tracer:start_trace({topic, <<"x/#">>}, all, "tmp/topic_trace.log"),
|
||||||
|
ok = emqx_tracer:start_trace({topic, <<"y/#">>}, all, "tmp/topic_trace.log"),
|
||||||
|
ct:sleep(100),
|
||||||
|
|
||||||
|
%% Verify the tracing file exits
|
||||||
|
?assert(filelib:is_regular("tmp/topic_trace.log")),
|
||||||
|
|
||||||
|
%% Get current traces
|
||||||
|
?assertEqual([{{topic,"x/#"},{debug,"tmp/topic_trace.log"}},
|
||||||
|
{{topic,"y/#"},{debug,"tmp/topic_trace.log"}}], emqx_tracer:lookup_traces()),
|
||||||
|
|
||||||
|
%% set the overall log level to debug
|
||||||
|
emqx_logger:set_log_level(debug),
|
||||||
|
|
||||||
|
%% Client with clientid = "client" publishes a "hi" message to "x/y/z".
|
||||||
|
emqtt:publish(T, <<"x/y/z">>, <<"hi">>),
|
||||||
|
ct:sleep(200),
|
||||||
|
|
||||||
|
?assert(filelib:file_size("tmp/topic_trace.log") > 0),
|
||||||
|
|
||||||
|
%% Stop tracing
|
||||||
|
ok = emqx_tracer:stop_trace({topic, <<"x/#">>}),
|
||||||
|
ok = emqx_tracer:stop_trace({topic, <<"y/#">>}),
|
||||||
|
{error, _Reason} = emqx_tracer:stop_trace({topic, <<"z/#">>}),
|
||||||
|
emqtt:disconnect(T),
|
||||||
|
|
||||||
|
emqx_logger:set_log_level(warning).
|
||||||
|
|
Loading…
Reference in New Issue