Merge pull request #7838 from terry-xiaoyu/fix_ci_emqx_modules
fix(test): race condition in emqx_telemetry_SUITE
This commit is contained in:
commit
0c059eb653
|
@ -0,0 +1,3 @@
|
||||||
|
data/
|
||||||
|
etc/certs/
|
||||||
|
etc/emqx.conf.all.rendered
|
|
@ -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]) ->
|
||||||
|
|
|
@ -140,9 +140,15 @@ init_per_testcase(t_exhook_info, Config) ->
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ok, _} = emqx_exhook_demo_svr:start(),
|
{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 = emqx_common_test_helpers:load_config(emqx_exhook_schema, ExhookConf),
|
||||||
{ok, _} = application:ensure_all_started(emqx_exhook),
|
{ok, _} = application:ensure_all_started(emqx_exhook),
|
||||||
Config;
|
Config;
|
||||||
|
init_per_testcase(t_cluster_uuid, Config) ->
|
||||||
|
Node = start_slave(n1),
|
||||||
|
ok = setup_slave(Node),
|
||||||
|
[{n1, Node} | Config];
|
||||||
init_per_testcase(_Testcase, Config) ->
|
init_per_testcase(_Testcase, Config) ->
|
||||||
mock_httpc(),
|
mock_httpc(),
|
||||||
Config.
|
Config.
|
||||||
|
@ -188,6 +194,9 @@ end_per_testcase(t_exhook_info, _Config) ->
|
||||||
emqx_exhook_demo_svr:stop(),
|
emqx_exhook_demo_svr:stop(),
|
||||||
application:stop(emqx_exhook),
|
application:stop(emqx_exhook),
|
||||||
ok;
|
ok;
|
||||||
|
end_per_testcase(t_cluster_uuid, Config) ->
|
||||||
|
Node = proplists:get_value(n1, Config),
|
||||||
|
ok = stop_slave(Node);
|
||||||
end_per_testcase(_Testcase, _Config) ->
|
end_per_testcase(_Testcase, _Config) ->
|
||||||
meck:unload([httpc]),
|
meck:unload([httpc]),
|
||||||
ok.
|
ok.
|
||||||
|
@ -211,23 +220,16 @@ t_node_uuid(_) ->
|
||||||
?assertEqual(NodeUUID3, NodeUUID4),
|
?assertEqual(NodeUUID3, NodeUUID4),
|
||||||
?assertMatch({badrpc, nodedown}, emqx_telemetry_proto_v1:get_node_uuid('fake@node')).
|
?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, ClusterUUID0} = emqx_telemetry:get_cluster_uuid(),
|
||||||
{ok, ClusterUUID1} = emqx_telemetry_proto_v1:get_cluster_uuid(node()),
|
{ok, ClusterUUID1} = emqx_telemetry_proto_v1:get_cluster_uuid(node()),
|
||||||
?assertEqual(ClusterUUID0, ClusterUUID1),
|
?assertEqual(ClusterUUID0, ClusterUUID1),
|
||||||
{ok, NodeUUID0} = emqx_telemetry:get_node_uuid(),
|
{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),
|
{ok, ClusterUUID2} = emqx_telemetry_proto_v1:get_cluster_uuid(Node),
|
||||||
?assertEqual(ClusterUUID0, ClusterUUID2),
|
?assertEqual(ClusterUUID0, ClusterUUID2),
|
||||||
{ok, NodeUUID1} = emqx_telemetry_proto_v1:get_node_uuid(Node),
|
{ok, NodeUUID1} = emqx_telemetry_proto_v1:get_node_uuid(Node),
|
||||||
?assertNotEqual(NodeUUID0, NodeUUID1),
|
?assertNotEqual(NodeUUID0, NodeUUID1),
|
||||||
ok
|
|
||||||
after
|
|
||||||
ok = stop_slave(Node)
|
|
||||||
end,
|
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
t_official_version(_) ->
|
t_official_version(_) ->
|
||||||
|
@ -674,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()), "@"),
|
||||||
|
|
|
@ -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).
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue