test(slowsub): update and simplify testsuite setup
This commit is contained in:
parent
d0e507eba4
commit
b15e81baf2
|
@ -20,76 +20,51 @@
|
||||||
-compile(nowarn_export_all).
|
-compile(nowarn_export_all).
|
||||||
|
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
-include_lib("common_test/include/ct.hrl").
|
||||||
-include_lib("emqx/include/emqx_mqtt.hrl").
|
-include_lib("emqx/include/emqx_mqtt.hrl").
|
||||||
-include_lib("emqx/include/emqx.hrl").
|
-include_lib("emqx/include/emqx.hrl").
|
||||||
-include_lib("emqx_slow_subs/include/emqx_slow_subs.hrl").
|
-include_lib("emqx_slow_subs/include/emqx_slow_subs.hrl").
|
||||||
|
|
||||||
-define(NOW, erlang:system_time(millisecond)).
|
-define(NOW, erlang:system_time(millisecond)).
|
||||||
-define(CLUSTER_RPC_SHARD, emqx_cluster_rpc_shard).
|
|
||||||
-define(LANTENCY, 101).
|
-define(LANTENCY, 101).
|
||||||
|
|
||||||
-define(BASE_CONF, <<
|
-define(BASE_CONF, <<
|
||||||
""
|
|
||||||
"\n"
|
|
||||||
"slow_subs {\n"
|
"slow_subs {\n"
|
||||||
" enable = true\n"
|
" enable = true\n"
|
||||||
" top_k_num = 5\n"
|
" top_k_num = 5\n"
|
||||||
" threshold = 100ms\n"
|
" threshold = 100ms\n"
|
||||||
" expire_interval = 5m\n"
|
" expire_interval = 5m\n"
|
||||||
" stats_type = whole\n"
|
" stats_type = whole\n"
|
||||||
" }"
|
"}"
|
||||||
""
|
|
||||||
>>).
|
>>).
|
||||||
|
|
||||||
all() ->
|
all() ->
|
||||||
emqx_common_test_helpers:all(?MODULE).
|
emqx_common_test_helpers:all(?MODULE).
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
application:load(emqx_conf),
|
Apps = emqx_cth_suite:start(
|
||||||
ok = ekka:start(),
|
[
|
||||||
ok = mria_rlog:wait_for_shards([?CLUSTER_RPC_SHARD], infinity),
|
emqx,
|
||||||
meck:new(emqx_alarm, [non_strict, passthrough, no_link]),
|
emqx_conf,
|
||||||
meck:expect(emqx_alarm, activate, 3, ok),
|
{emqx_slow_subs, ?BASE_CONF}
|
||||||
meck:expect(emqx_alarm, deactivate, 3, ok),
|
],
|
||||||
|
#{work_dir => emqx_cth_suite:work_dir(Config)}
|
||||||
|
),
|
||||||
|
[{suite_apps, Apps} | Config].
|
||||||
|
|
||||||
ok = emqx_common_test_helpers:load_config(emqx_slow_subs_schema, ?BASE_CONF),
|
end_per_suite(Config) ->
|
||||||
emqx_common_test_helpers:start_apps([emqx_slow_subs]),
|
ok = emqx_cth_suite:stop(?config(suite_apps, Config)).
|
||||||
Config.
|
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
|
||||||
ekka:stop(),
|
|
||||||
mria:stop(),
|
|
||||||
mria_mnesia:delete_schema(),
|
|
||||||
meck:unload(emqx_alarm),
|
|
||||||
|
|
||||||
emqx_common_test_helpers:stop_apps([emqx_slow_subs]).
|
|
||||||
|
|
||||||
init_per_testcase(t_expire, Config) ->
|
|
||||||
{ok, _} = emqx_cluster_rpc:start_link(),
|
|
||||||
update_config(<<"expire_interval">>, <<"1500ms">>),
|
|
||||||
Config;
|
|
||||||
init_per_testcase(_, Config) ->
|
|
||||||
{ok, _} = emqx_cluster_rpc:start_link(),
|
|
||||||
Config.
|
|
||||||
|
|
||||||
end_per_testcase(_, _) ->
|
|
||||||
case erlang:whereis(node()) of
|
|
||||||
undefined ->
|
|
||||||
ok;
|
|
||||||
P ->
|
|
||||||
erlang:unlink(P),
|
|
||||||
erlang:exit(P, kill)
|
|
||||||
end,
|
|
||||||
ok.
|
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Test Cases
|
%% Test Cases
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
t_pub(_) ->
|
t_pub(_) ->
|
||||||
_ = [stats_with_type(Type) || Type <- [whole, internal, response]],
|
_ = [stats_with_type(Type) || Type <- [whole, internal, response]],
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
t_expire(_) ->
|
t_expire(_) ->
|
||||||
|
_ = update_config(<<"expire_interval">>, <<"1500ms">>),
|
||||||
Now = ?NOW,
|
Now = ?NOW,
|
||||||
Each = fun(I) ->
|
Each = fun(I) ->
|
||||||
ClientId = erlang:list_to_binary(io_lib:format("test_~p", [I])),
|
ClientId = erlang:list_to_binary(io_lib:format("test_~p", [I])),
|
||||||
|
|
|
@ -20,10 +20,8 @@
|
||||||
-compile(nowarn_export_all).
|
-compile(nowarn_export_all).
|
||||||
|
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
-include_lib("common_test/include/ct.hrl").
|
||||||
-include_lib("emqx/include/emqx.hrl").
|
-include_lib("emqx/include/emqx.hrl").
|
||||||
-include_lib("emqx/include/emqx_mqtt.hrl").
|
|
||||||
-include_lib("emqx_management/include/emqx_mgmt.hrl").
|
|
||||||
-include_lib("emqx_slow_subs/include/emqx_slow_subs.hrl").
|
-include_lib("emqx_slow_subs/include/emqx_slow_subs.hrl").
|
||||||
|
|
||||||
-define(HOST, "http://127.0.0.1:18083/").
|
-define(HOST, "http://127.0.0.1:18083/").
|
||||||
|
@ -32,63 +30,43 @@
|
||||||
|
|
||||||
-define(BASE_PATH, "api").
|
-define(BASE_PATH, "api").
|
||||||
-define(NOW, erlang:system_time(millisecond)).
|
-define(NOW, erlang:system_time(millisecond)).
|
||||||
-define(CLUSTER_RPC_SHARD, emqx_cluster_rpc_shard).
|
|
||||||
|
|
||||||
-define(CONF_DEFAULT, <<
|
-define(CONF_DEFAULT, <<
|
||||||
""
|
"slow_subs {\n"
|
||||||
"\n"
|
|
||||||
"slow_subs\n"
|
|
||||||
"{\n"
|
|
||||||
" enable = true\n"
|
" enable = true\n"
|
||||||
" top_k_num = 5,\n"
|
" top_k_num = 5,\n"
|
||||||
" expire_interval = 60s\n"
|
" expire_interval = 60s\n"
|
||||||
" stats_type = whole\n"
|
" stats_type = whole\n"
|
||||||
"}"
|
"}"
|
||||||
""
|
|
||||||
>>).
|
>>).
|
||||||
|
|
||||||
all() ->
|
all() ->
|
||||||
emqx_common_test_helpers:all(?MODULE).
|
emqx_common_test_helpers:all(?MODULE).
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
application:load(emqx_conf),
|
Apps = emqx_cth_suite:start(
|
||||||
ok = ekka:start(),
|
[
|
||||||
ok = mria_rlog:wait_for_shards([?CLUSTER_RPC_SHARD], infinity),
|
emqx,
|
||||||
meck:new(emqx_alarm, [non_strict, passthrough, no_link]),
|
emqx_auth,
|
||||||
meck:expect(emqx_alarm, activate, 3, ok),
|
emqx_conf,
|
||||||
meck:expect(emqx_alarm, deactivate, 3, ok),
|
emqx_management,
|
||||||
|
{emqx_slow_subs, ?CONF_DEFAULT},
|
||||||
ok = emqx_common_test_helpers:load_config(emqx_slow_subs_schema, ?CONF_DEFAULT),
|
{emqx_dashboard, "dashboard.listeners.http { enable = true, bind = 18083 }"}
|
||||||
emqx_mgmt_api_test_util:init_suite([emqx_slow_subs]),
|
],
|
||||||
{ok, _} = application:ensure_all_started(emqx_auth),
|
#{work_dir => emqx_cth_suite:work_dir(Config)}
|
||||||
Config.
|
),
|
||||||
|
_ = emqx_common_test_http:create_default_app(),
|
||||||
|
[{suite_apps, Apps} | Config].
|
||||||
|
|
||||||
end_per_suite(Config) ->
|
end_per_suite(Config) ->
|
||||||
ekka:stop(),
|
ok = emqx_cth_suite:stop(?config(suite_apps, Config)).
|
||||||
mria:stop(),
|
|
||||||
mria_mnesia:delete_schema(),
|
|
||||||
meck:unload(emqx_alarm),
|
|
||||||
|
|
||||||
application:stop(emqx_auth),
|
|
||||||
emqx_mgmt_api_test_util:end_suite([emqx_slow_subs]),
|
|
||||||
Config.
|
|
||||||
|
|
||||||
init_per_testcase(_, Config) ->
|
init_per_testcase(_, Config) ->
|
||||||
{ok, _} = emqx_cluster_rpc:start_link(),
|
{ok, _} = application:ensure_all_started(emqx_slow_subs),
|
||||||
application:ensure_all_started(emqx_slow_subs),
|
|
||||||
timer:sleep(500),
|
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
end_per_testcase(_, Config) ->
|
end_per_testcase(_, _Config) ->
|
||||||
application:stop(emqx_slow_subs),
|
ok = application:stop(emqx_slow_subs).
|
||||||
case erlang:whereis(node()) of
|
|
||||||
undefined ->
|
|
||||||
ok;
|
|
||||||
P ->
|
|
||||||
erlang:unlink(P),
|
|
||||||
erlang:exit(P, kill)
|
|
||||||
end,
|
|
||||||
Config.
|
|
||||||
|
|
||||||
t_get_history(_) ->
|
t_get_history(_) ->
|
||||||
Now = ?NOW,
|
Now = ?NOW,
|
||||||
|
|
Loading…
Reference in New Issue