Sfoglia il codice sorgente

test: fix flaky test emqx_ctl_SUITE.erl

Zaiming (Stone) Shi 3 anni fa
parent
commit
a4d0a9266a
2 ha cambiato i file con 14 aggiunte e 3 eliminazioni
  1. 7 1
      apps/emqx/src/emqx_ctl.erl
  2. 7 2
      apps/emqx/test/emqx_ctl_SUITE.erl

+ 7 - 1
apps/emqx/src/emqx_ctl.erl

@@ -75,7 +75,13 @@ start_link() ->
     gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
 
 -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.
 register_command(Cmd, MF) when is_atom(Cmd) ->

+ 7 - 2
apps/emqx/test/emqx_ctl_SUITE.erl

@@ -107,9 +107,14 @@ cmd2_fun(["arg1", "arg2"]) -> ok;
 cmd2_fun(["arg1", "badarg"]) -> error(badarg).
 
 with_ctl_server(Fun) ->
+    ok = emqx_ctl:stop(),
     {ok, Pid} = emqx_ctl:start_link(),
-    _ = Fun(Pid),
-    ok = emqx_ctl:stop().
+    try
+        _ = Fun(Pid),
+        ok
+    after
+        ok = emqx_ctl:stop()
+    end.
 
 mock_print() ->
     %% proxy usage/1,2 and print/1,2 to format_xx/1,2 funcs