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

This commit is contained in:
Shawn 2022-04-29 15:12:01 +08:00
parent bef00b461e
commit ef0e6d7fd8
3 changed files with 15 additions and 5 deletions

View File

@ -66,9 +66,14 @@ start() ->
start(?NAME, ?PORT). start(?NAME, ?PORT).
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), 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() ->
stop(?NAME). stop(?NAME).
@ -87,7 +92,7 @@ take() ->
in({FunName, Req}) -> in({FunName, Req}) ->
to_atom_name(?NAME) ! {in, FunName, Req}. to_atom_name(?NAME) ! {in, FunName, Req}.
mgr_main(Name, Port) -> mgr_main(Parent, Name, Port) ->
application:ensure_all_started(grpc), application:ensure_all_started(grpc),
Services = #{ Services = #{
protos => [emqx_exhook_pb], protos => [emqx_exhook_pb],
@ -95,6 +100,7 @@ mgr_main(Name, Port) ->
}, },
Options = [], Options = [],
Svr = grpc:start_server(Name, Port, Services, Options), Svr = grpc:start_server(Name, Port, Services, Options),
Parent ! grpc_server_started,
mgr_loop([Svr, queue:new(), queue:new()]). mgr_loop([Svr, queue:new(), queue:new()]).
mgr_loop([Svr, Q, Takes]) -> mgr_loop([Svr, Q, Takes]) ->

View File

@ -140,7 +140,6 @@ init_per_testcase(t_exhook_info, Config) ->
} }
}, },
{ok, _} = emqx_exhook_demo_svr:start(), {ok, _} = emqx_exhook_demo_svr:start(),
timer:sleep(2000),
{ok, Sock} = gen_tcp:connect("localhost", 9000, [], 3000), {ok, Sock} = gen_tcp:connect("localhost", 9000, [], 3000),
_ = gen_tcp:close(Sock), _ = gen_tcp:close(Sock),
ok = emqx_common_test_helpers:load_config(emqx_exhook_schema, ExhookConf), ok = emqx_common_test_helpers:load_config(emqx_exhook_schema, ExhookConf),
@ -677,7 +676,10 @@ setup_slave(Node) ->
ok. ok.
stop_slave(Node) -> 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() ->
[_, Host] = string:tokens(atom_to_list(node()), "@"), [_, Host] = string:tokens(atom_to_list(node()), "@"),

View File

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