Improve coverage for emqx_hooks, and add test case for emqx_mod_sup (#1892)
Improve coverage for emqx_hooks, and add test case for emqx_mod_sup
This commit is contained in:
parent
73658b3953
commit
873a08dc94
3
Makefile
3
Makefile
|
@ -35,10 +35,9 @@ EUNIT_OPTS = verbose
|
|||
# CT_SUITES = emqx_frame
|
||||
## emqx_trie emqx_router emqx_frame emqx_mqtt_compat
|
||||
|
||||
|
||||
CT_SUITES = emqx emqx_client emqx_zone emqx_banned emqx_connection emqx_session \
|
||||
emqx_access emqx_broker emqx_cm emqx_frame emqx_guid emqx_inflight emqx_json \
|
||||
emqx_keepalive emqx_lib emqx_metrics emqx_mod emqx_mqtt_caps \
|
||||
emqx_keepalive emqx_lib emqx_metrics emqx_mod emqx_mod_sup emqx_mqtt_caps \
|
||||
emqx_mqtt_props emqx_mqueue emqx_net emqx_pqueue emqx_router emqx_sm \
|
||||
emqx_tables emqx_time emqx_topic emqx_trie emqx_vm emqx_mountpoint \
|
||||
emqx_listeners emqx_protocol emqx_pool emqx_shared_sub
|
||||
|
|
|
@ -43,7 +43,7 @@ add_delete_hook(_) ->
|
|||
{callback, {?MODULE, hook_fun2, []}, undefined, 8}],
|
||||
?assertEqual(Callbacks2, emqx_hooks:lookup(emqx_hook)),
|
||||
ok = emqx:unhook(emqx_hook, {?MODULE, hook_fun1, []}),
|
||||
ok = emqx:unhook(emqx_hook, {?MODULE, hook_fun2, []}),
|
||||
ok = emqx:unhook(emqx_hook, {?MODULE, hook_fun2}),
|
||||
timer:sleep(1000),
|
||||
?assertEqual([], emqx_hooks:lookup(emqx_hook)),
|
||||
ok = emqx_hooks:stop().
|
||||
|
@ -62,6 +62,17 @@ run_hooks(_) ->
|
|||
ok = emqx:hook(foreach_hook, fun ?MODULE:hook_fun7/2, [initArg]),
|
||||
ok = emqx:hook(foreach_hook, fun ?MODULE:hook_fun8/2, [initArg]),
|
||||
stop = emqx:run_hooks(foreach_hook, [arg]),
|
||||
|
||||
ok = emqx:hook(foldl_hook2, fun ?MODULE:hook_fun9/2),
|
||||
ok = emqx:hook(foldl_hook2, {?MODULE, hook_fun10, []}),
|
||||
{stop, []} = emqx:run_hooks(foldl_hook2, [arg], []),
|
||||
|
||||
ok = emqx:hook(filter1_hook, {?MODULE, hook_fun1, []}, {?MODULE, hook_filter1, []}, 0),
|
||||
ok = emqx:run_hooks(filter1_hook, [arg]),
|
||||
|
||||
ok = emqx:hook(filter2_hook, {?MODULE, hook_fun2, []}, {?MODULE, hook_filter2, []}),
|
||||
{ok, []} = emqx:run_hooks(filter2_hook, [arg], []),
|
||||
|
||||
ok = emqx_hooks:stop().
|
||||
|
||||
hook_fun1([]) -> ok.
|
||||
|
@ -75,3 +86,9 @@ hook_fun6(arg, initArg) -> ok.
|
|||
hook_fun7(arg, initArg) -> any.
|
||||
hook_fun8(arg, initArg) -> stop.
|
||||
|
||||
hook_fun9(arg, _Acc) -> any.
|
||||
hook_fun10(arg, _Acc) -> stop.
|
||||
|
||||
hook_filter1(arg) -> true.
|
||||
hook_filter2(arg, _Acc) -> true.
|
||||
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
%% Copyright (c) 2018 EMQ Technologies Co., Ltd. All Rights Reserved.
|
||||
%%
|
||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||
%% you may not use this file except in compliance with the License.
|
||||
%% You may obtain a copy of the License at
|
||||
%%
|
||||
%% http://www.apache.org/licenses/LICENSE-2.0
|
||||
%%
|
||||
%% Unless required by applicable law or agreed to in writing, software
|
||||
%% distributed under the License is distributed on an "AS IS" BASIS,
|
||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
%% See the License for the specific language governing permissions and
|
||||
%% limitations under the License.
|
||||
|
||||
-module(emqx_mod_sup_SUITE).
|
||||
|
||||
-compile(export_all).
|
||||
-compile(nowarn_export_all).
|
||||
|
||||
-include("emqx.hrl").
|
||||
|
||||
all() -> [t_child_all].
|
||||
|
||||
t_child_all(_) ->
|
||||
{ok, _Pid} = emqx_mod_sup:start_link(),
|
||||
{ok, _Child} = emqx_mod_sup:start_child(emqx_banned, worker),
|
||||
timer:sleep(10),
|
||||
ok = emqx_mod_sup:stop_child(emqx_banned).
|
Loading…
Reference in New Issue