Merge pull request #7838 from terry-xiaoyu/fix_ci_emqx_modules

fix(test): race condition in emqx_telemetry_SUITE
This commit is contained in:
zhouzb 2022-04-29 18:50:43 +08:00 committed by GitHub
commit 0c059eb653
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 17 deletions

3
apps/emqx_conf/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
data/
etc/certs/
etc/emqx.conf.all.rendered

View File

@ -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]) ->

View File

@ -140,9 +140,15 @@ init_per_testcase(t_exhook_info, Config) ->
}
},
{ok, _} = emqx_exhook_demo_svr:start(),
{ok, Sock} = gen_tcp:connect("localhost", 9000, [], 3000),
_ = gen_tcp:close(Sock),
ok = emqx_common_test_helpers:load_config(emqx_exhook_schema, ExhookConf),
{ok, _} = application:ensure_all_started(emqx_exhook),
Config;
init_per_testcase(t_cluster_uuid, Config) ->
Node = start_slave(n1),
ok = setup_slave(Node),
[{n1, Node} | Config];
init_per_testcase(_Testcase, Config) ->
mock_httpc(),
Config.
@ -188,6 +194,9 @@ end_per_testcase(t_exhook_info, _Config) ->
emqx_exhook_demo_svr:stop(),
application:stop(emqx_exhook),
ok;
end_per_testcase(t_cluster_uuid, Config) ->
Node = proplists:get_value(n1, Config),
ok = stop_slave(Node);
end_per_testcase(_Testcase, _Config) ->
meck:unload([httpc]),
ok.
@ -211,23 +220,16 @@ t_node_uuid(_) ->
?assertEqual(NodeUUID3, NodeUUID4),
?assertMatch({badrpc, nodedown}, emqx_telemetry_proto_v1:get_node_uuid('fake@node')).
t_cluster_uuid(_Config) ->
t_cluster_uuid(Config) ->
Node = proplists:get_value(n1, Config),
{ok, ClusterUUID0} = emqx_telemetry:get_cluster_uuid(),
{ok, ClusterUUID1} = emqx_telemetry_proto_v1:get_cluster_uuid(node()),
?assertEqual(ClusterUUID0, ClusterUUID1),
{ok, NodeUUID0} = emqx_telemetry:get_node_uuid(),
Node = start_slave(n1),
try
ok = setup_slave(Node),
{ok, ClusterUUID2} = emqx_telemetry_proto_v1:get_cluster_uuid(Node),
?assertEqual(ClusterUUID0, ClusterUUID2),
{ok, NodeUUID1} = emqx_telemetry_proto_v1:get_node_uuid(Node),
?assertNotEqual(NodeUUID0, NodeUUID1),
ok
after
ok = stop_slave(Node)
end,
ok.
t_official_version(_) ->
@ -674,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()), "@"),

View File

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