Merge pull request #7829 from zmstone/0428-test-fix-flaky-test-emqx_ctl_SUITE
test: fix flaky test emqx_ctl_SUITE.erl
This commit is contained in:
commit
7997655f02
|
@ -75,7 +75,13 @@ start_link() ->
|
||||||
gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
|
gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
|
||||||
|
|
||||||
-spec stop() -> ok.
|
-spec stop() -> ok.
|
||||||
stop() -> gen_server:stop(?SERVER).
|
stop() ->
|
||||||
|
try
|
||||||
|
gen_server:stop(?SERVER)
|
||||||
|
catch
|
||||||
|
exit:R when R =:= noproc orelse R =:= timeout ->
|
||||||
|
ok
|
||||||
|
end.
|
||||||
|
|
||||||
-spec register_command(cmd(), {module(), atom()}) -> ok.
|
-spec register_command(cmd(), {module(), atom()}) -> ok.
|
||||||
register_command(Cmd, MF) when is_atom(Cmd) ->
|
register_command(Cmd, MF) when is_atom(Cmd) ->
|
||||||
|
@ -105,8 +111,9 @@ run_command(help, []) ->
|
||||||
run_command(Cmd, Args) when is_atom(Cmd) ->
|
run_command(Cmd, Args) when is_atom(Cmd) ->
|
||||||
case lookup_command(Cmd) of
|
case lookup_command(Cmd) of
|
||||||
[{Mod, Fun}] ->
|
[{Mod, Fun}] ->
|
||||||
try Mod:Fun(Args) of
|
try
|
||||||
_ -> ok
|
_ = apply(Mod, Fun, [Args]),
|
||||||
|
ok
|
||||||
catch
|
catch
|
||||||
_:Reason:Stacktrace ->
|
_:Reason:Stacktrace ->
|
||||||
?SLOG(error, #{
|
?SLOG(error, #{
|
||||||
|
@ -141,7 +148,7 @@ help() ->
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun({_, {Mod, Cmd}, _}) ->
|
fun({_, {Mod, Cmd}, _}) ->
|
||||||
print("~110..-s~n", [""]),
|
print("~110..-s~n", [""]),
|
||||||
Mod:Cmd(usage)
|
apply(Mod, Cmd, [usage])
|
||||||
end,
|
end,
|
||||||
Cmds
|
Cmds
|
||||||
)
|
)
|
||||||
|
|
|
@ -107,9 +107,14 @@ cmd2_fun(["arg1", "arg2"]) -> ok;
|
||||||
cmd2_fun(["arg1", "badarg"]) -> error(badarg).
|
cmd2_fun(["arg1", "badarg"]) -> error(badarg).
|
||||||
|
|
||||||
with_ctl_server(Fun) ->
|
with_ctl_server(Fun) ->
|
||||||
|
ok = emqx_ctl:stop(),
|
||||||
{ok, Pid} = emqx_ctl:start_link(),
|
{ok, Pid} = emqx_ctl:start_link(),
|
||||||
|
try
|
||||||
_ = Fun(Pid),
|
_ = Fun(Pid),
|
||||||
ok = emqx_ctl:stop().
|
ok
|
||||||
|
after
|
||||||
|
ok = emqx_ctl:stop()
|
||||||
|
end.
|
||||||
|
|
||||||
mock_print() ->
|
mock_print() ->
|
||||||
%% proxy usage/1,2 and print/1,2 to format_xx/1,2 funcs
|
%% proxy usage/1,2 and print/1,2 to format_xx/1,2 funcs
|
||||||
|
|
Loading…
Reference in New Issue