chore(topic_metrics): do not complain on nonexisting ets while topic metrics stop
This commit is contained in:
parent
4d60b0da1d
commit
791010a65c
|
@ -1,7 +1,7 @@
|
|||
%% -*- mode: erlang -*-
|
||||
{application, emqx_modules, [
|
||||
{description, "EMQX Modules"},
|
||||
{vsn, "5.0.13"},
|
||||
{vsn, "5.0.14"},
|
||||
{modules, []},
|
||||
{applications, [kernel, stdlib, emqx, emqx_ctl]},
|
||||
{mod, {emqx_modules_app, []}},
|
||||
|
|
|
@ -179,7 +179,12 @@ deregister_all() ->
|
|||
gen_server:call(?MODULE, {deregister, all}).
|
||||
|
||||
is_registered(Topic) ->
|
||||
ets:member(?TAB, Topic).
|
||||
try
|
||||
ets:member(?TAB, Topic)
|
||||
catch
|
||||
error:badarg ->
|
||||
false
|
||||
end.
|
||||
|
||||
all_registered_topics() ->
|
||||
[Topic || {Topic, _} <- ets:tab2list(?TAB)].
|
||||
|
|
|
@ -42,6 +42,9 @@ init_per_testcase(_Case, Config) ->
|
|||
emqx_topic_metrics:deregister_all(),
|
||||
Config.
|
||||
|
||||
end_per_testcase(t_metrics_not_started, _Config) ->
|
||||
_ = supervisor:restart_child(emqx_modules_sup, emqx_topic_metrics),
|
||||
ok;
|
||||
end_per_testcase(_Case, _Config) ->
|
||||
emqx_topic_metrics:deregister_all(),
|
||||
emqx_config:put([topic_metrics], []),
|
||||
|
@ -181,3 +184,10 @@ t_unknown_messages(_) ->
|
|||
OldPid,
|
||||
whereis(emqx_topic_metrics)
|
||||
).
|
||||
|
||||
t_metrics_not_started(_Config) ->
|
||||
_ = emqx_topic_metrics:register(<<"a/b/c">>),
|
||||
?assert(emqx_topic_metrics:is_registered(<<"a/b/c">>)),
|
||||
ok = supervisor:terminate_child(emqx_modules_sup, emqx_topic_metrics),
|
||||
?assertNot(emqx_topic_metrics:is_registered(<<"a/b/c">>)),
|
||||
{ok, _} = supervisor:restart_child(emqx_modules_sup, emqx_topic_metrics).
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Do not emit useless crash report when EMQX stops.
|
||||
Previously, when EMQX (and `emqx_topic_metrics` in particular) stopped and removed underlying tables, some messages were still being handled and crashed.
|
Loading…
Reference in New Issue