fix(exhook): set trap_exit flag

This commit is contained in:
JianBo He 2021-08-11 18:21:16 +08:00
parent f5acf5fd0b
commit 6574fc4f14
3 changed files with 10 additions and 9 deletions

View File

@ -101,6 +101,7 @@ call(Pid, Req) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
init([Servers, AutoReconnect, ReqOpts]) -> init([Servers, AutoReconnect, ReqOpts]) ->
process_flag(trap_exit, true),
%% XXX: Due to the ExHook Module in the enterprise, %% XXX: Due to the ExHook Module in the enterprise,
%% this process may start multiple times and they will share this table %% this process may start multiple times and they will share this table
try try
@ -182,11 +183,11 @@ handle_info({timeout, _Ref, {reload, Name}}, State) ->
handle_info(_Info, State) -> handle_info(_Info, State) ->
{noreply, State}. {noreply, State}.
terminate(_Reason, State = #state{stopped = Stopped}) -> terminate(_Reason, State = #state{running = Running}) ->
_ = maps:fold(fun(Name, _, AccIn) -> _ = maps:fold(fun(Name, _, AccIn) ->
{ok, NAccIn} = do_unload_server(Name, AccIn), {ok, NAccIn} = do_unload_server(Name, AccIn),
NAccIn NAccIn
end, State, Stopped), end, State, Running),
_ = unload_exhooks(), _ = unload_exhooks(),
ok. ok.

View File

@ -30,6 +30,7 @@
#{ id => Mod #{ id => Mod
, start => {Mod, start_link, Args} , start => {Mod, start_link, Args}
, type => Type , type => Type
, shutdown => 15000
} }
). ).

View File

@ -53,15 +53,14 @@ end_per_suite(_Cfg) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
t_noserver_nohook(_) -> t_noserver_nohook(_) ->
emqx_exhook:disable(<<"default">>), emqx_exhook:disable(default),
?assertEqual([], loaded_exhook_hookpoints()), ?assertEqual([], ets:tab2list(emqx_hooks)),
[#{name := Name} = Opts] = emqx_config:get([exhook, servers]), ok = emqx_exhook:enable(default),
ok = emqx_exhook:enable(Name, Opts), ?assertNotEqual([], ets:tab2list(emqx_hooks)).
?assertNotEqual([], loaded_exhook_hookpoints()).
t_cli_list(_) -> t_cli_list(_) ->
meck_print(), meck_print(),
?assertEqual( [[emqx_exhook_server:format(Svr) || Svr <- emqx_exhook:list()]] ?assertEqual( [[emqx_exhook_server:format(emqx_exhook_mngr:server(Name)) || Name <- emqx_exhook:list()]]
, emqx_exhook_cli:cli(["server", "list"]) , emqx_exhook_cli:cli(["server", "list"])
), ),
unmeck_print(). unmeck_print().
@ -70,7 +69,7 @@ t_cli_enable_disable(_) ->
meck_print(), meck_print(),
?assertEqual([already_started], emqx_exhook_cli:cli(["server", "enable", "default"])), ?assertEqual([already_started], emqx_exhook_cli:cli(["server", "enable", "default"])),
?assertEqual(ok, emqx_exhook_cli:cli(["server", "disable", "default"])), ?assertEqual(ok, emqx_exhook_cli:cli(["server", "disable", "default"])),
?assertEqual([], emqx_exhook_cli:cli(["server", "list"])), ?assertEqual([["name=default, hooks=#{}, active=false"]], emqx_exhook_cli:cli(["server", "list"])),
?assertEqual([not_running], emqx_exhook_cli:cli(["server", "disable", "default"])), ?assertEqual([not_running], emqx_exhook_cli:cli(["server", "disable", "default"])),
?assertEqual(ok, emqx_exhook_cli:cli(["server", "enable", "default"])), ?assertEqual(ok, emqx_exhook_cli:cli(["server", "enable", "default"])),