chore(topic_metrics): do not complain on nonexisting ets while topic metrics stop

This commit is contained in:
Ilya Averyanov 2023-05-02 15:43:06 +03:00
parent 4d60b0da1d
commit 791010a65c
4 changed files with 19 additions and 2 deletions

View File

@ -1,7 +1,7 @@
%% -*- mode: erlang -*- %% -*- mode: erlang -*-
{application, emqx_modules, [ {application, emqx_modules, [
{description, "EMQX Modules"}, {description, "EMQX Modules"},
{vsn, "5.0.13"}, {vsn, "5.0.14"},
{modules, []}, {modules, []},
{applications, [kernel, stdlib, emqx, emqx_ctl]}, {applications, [kernel, stdlib, emqx, emqx_ctl]},
{mod, {emqx_modules_app, []}}, {mod, {emqx_modules_app, []}},

View File

@ -179,7 +179,12 @@ deregister_all() ->
gen_server:call(?MODULE, {deregister, all}). gen_server:call(?MODULE, {deregister, all}).
is_registered(Topic) -> is_registered(Topic) ->
ets:member(?TAB, Topic). try
ets:member(?TAB, Topic)
catch
error:badarg ->
false
end.
all_registered_topics() -> all_registered_topics() ->
[Topic || {Topic, _} <- ets:tab2list(?TAB)]. [Topic || {Topic, _} <- ets:tab2list(?TAB)].

View File

@ -42,6 +42,9 @@ init_per_testcase(_Case, Config) ->
emqx_topic_metrics:deregister_all(), emqx_topic_metrics:deregister_all(),
Config. Config.
end_per_testcase(t_metrics_not_started, _Config) ->
_ = supervisor:restart_child(emqx_modules_sup, emqx_topic_metrics),
ok;
end_per_testcase(_Case, _Config) -> end_per_testcase(_Case, _Config) ->
emqx_topic_metrics:deregister_all(), emqx_topic_metrics:deregister_all(),
emqx_config:put([topic_metrics], []), emqx_config:put([topic_metrics], []),
@ -181,3 +184,10 @@ t_unknown_messages(_) ->
OldPid, OldPid,
whereis(emqx_topic_metrics) 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).

View File

@ -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.