fix(emqx_os_mon): log info level for unexpected message

also reply error for unexpected gen_server call
and refine log message for unexpected gen_server cast
This commit is contained in:
Zaiming Shi 2021-07-27 09:38:56 +02:00 committed by turtleDeng
parent a6b95afda8
commit d628d37a93
2 changed files with 5 additions and 5 deletions

View File

@ -85,11 +85,10 @@ init([]) ->
{ok, #{}}. {ok, #{}}.
handle_call(Req, _From, State) -> handle_call(Req, _From, State) ->
?LOG(error, "Unexpected call: ~p", [Req]), {reply, {error, {unexpected_call, Req}}, State}.
{reply, ignored, State}.
handle_cast(Msg, State) -> handle_cast(Msg, State) ->
?LOG(error, "Unexpected cast: ~p", [Msg]), ?LOG(error, "unexpected_cast_discarded: ~p", [Msg]),
{noreply, State}. {noreply, State}.
handle_info({timeout, _Timer, check}, State) -> handle_info({timeout, _Timer, check}, State) ->
@ -111,7 +110,7 @@ handle_info({timeout, _Timer, check}, State) ->
{noreply, State}; {noreply, State};
handle_info(Info, State) -> handle_info(Info, State) ->
?LOG(error, "unexpected info: ~p", [Info]), ?LOG(info, "unexpected_info_discarded: ~p", [Info]),
{noreply, State}. {noreply, State}.
terminate(_Reason, _State) -> terminate(_Reason, _State) ->

View File

@ -52,7 +52,8 @@ t_api(_) ->
?assertEqual(ok, emqx_os_mon:set_procmem_high_watermark(0.11)), ?assertEqual(ok, emqx_os_mon:set_procmem_high_watermark(0.11)),
?assertEqual(11, emqx_os_mon:get_procmem_high_watermark()), ?assertEqual(11, emqx_os_mon:get_procmem_high_watermark()),
?assertEqual(ignored, gen_server:call(emqx_os_mon, ignored)), ?assertEqual({error, {unexpected_call, ignored}},
gen_server:call(emqx_os_mon, ignored)),
?assertEqual(ok, gen_server:cast(emqx_os_mon, ignored)), ?assertEqual(ok, gen_server:cast(emqx_os_mon, ignored)),
emqx_os_mon ! ignored, emqx_os_mon ! ignored,
gen_server:stop(emqx_os_mon), gen_server:stop(emqx_os_mon),