Explorar el Código

fix(test): ensure the test node removed from the ekka cluster

Shawn hace 3 años
padre
commit
ef0e6d7fd8

+ 9 - 3
apps/emqx_exhook/test/emqx_exhook_demo_svr.erl

@@ -66,9 +66,14 @@ start() ->
     start(?NAME, ?PORT).
 
 start(Name, Port) ->
-    Pid = spawn(fun() -> mgr_main(Name, Port) end),
+    Parent = self(),
+    Pid = spawn(fun() -> mgr_main(Parent, Name, Port) end),
     register(to_atom_name(Name), Pid),
-    {ok, Pid}.
+    receive
+        grpc_server_started -> {ok, Pid}
+    after 2000 ->
+        error({failed_to_start_grpc_server, Port})
+    end.
 
 stop() ->
     stop(?NAME).
@@ -87,7 +92,7 @@ take() ->
 in({FunName, Req}) ->
     to_atom_name(?NAME) ! {in, FunName, Req}.
 
-mgr_main(Name, Port) ->
+mgr_main(Parent, Name, Port) ->
     application:ensure_all_started(grpc),
     Services = #{
         protos => [emqx_exhook_pb],
@@ -95,6 +100,7 @@ mgr_main(Name, Port) ->
     },
     Options = [],
     Svr = grpc:start_server(Name, Port, Services, Options),
+    Parent ! grpc_server_started,
     mgr_loop([Svr, queue:new(), queue:new()]).
 
 mgr_loop([Svr, Q, Takes]) ->

+ 4 - 2
apps/emqx_modules/test/emqx_telemetry_SUITE.erl

@@ -140,7 +140,6 @@ init_per_testcase(t_exhook_info, Config) ->
                 }
         },
     {ok, _} = emqx_exhook_demo_svr:start(),
-    timer:sleep(2000),
     {ok, Sock} = gen_tcp:connect("localhost", 9000, [], 3000),
     _ = gen_tcp:close(Sock),
     ok = emqx_common_test_helpers:load_config(emqx_exhook_schema, ExhookConf),
@@ -677,7 +676,10 @@ setup_slave(Node) ->
     ok.
 
 stop_slave(Node) ->
-    slave:stop(Node).
+    ok = ekka:force_leave(Node),
+    emqx_cluster_rpc:skip_failed_commit(Node),
+    ok = slave:stop(Node),
+    ?assertEqual([node()], mria_mnesia:running_nodes()).
 
 host() ->
     [_, Host] = string:tokens(atom_to_list(node()), "@"),

+ 2 - 0
apps/emqx_modules/test/emqx_topic_metrics_api_SUITE.erl

@@ -27,6 +27,8 @@
     <<"topic_metrics">> => []
 }).
 
+suite() -> [{timetrap, {seconds, 30}}].
+
 all() ->
     emqx_common_test_helpers:all(?MODULE).