Skip to content

Commit 9cf304c

Browse files
Merge pull request #12988 from rabbitmq/mergify/bp/v4.0.x/pr-12985
rabbitmq_peer_discovery_etcd: Wait for etcd start in system_SUITE (backport #12985)
2 parents 3548fd5 + 1c9918c commit 9cf304c

File tree

1 file changed

+50
-26
lines changed

1 file changed

+50
-26
lines changed

deps/rabbitmq_peer_discovery_etcd/test/system_SUITE.erl

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
init_per_testcase/2,
2727
end_per_testcase/2,
2828

29-
etcd_connection_sanity_check_test/1,
3029
init_opens_a_connection_test/1,
3130
registration_with_locking_test/1,
3231
start_one_member_at_a_time/1,
@@ -41,7 +40,6 @@ all() ->
4140
groups() ->
4241
[
4342
{v3_client, [], [
44-
etcd_connection_sanity_check_test,
4543
init_opens_a_connection_test,
4644
registration_with_locking_test
4745
]},
@@ -202,13 +200,57 @@ start_etcd(Config) ->
202200
"--initial-cluster-state", "new",
203201
"--initial-cluster-token", "test-token",
204202
"--log-level", "debug", "--log-outputs", "stdout"],
205-
EtcdPid = spawn(fun() -> rabbit_ct_helpers:exec(Cmd) end),
203+
EtcdPid = spawn(fun() -> do_start_etcd(Cmd) end),
206204

207-
EtcdEndpoint = rabbit_misc:format("~s:~b", [EtcdHost, EtcdClientPort]),
208-
rabbit_ct_helpers:set_config(
209-
Config,
210-
[{etcd_pid, EtcdPid},
211-
{etcd_endpoints, [EtcdEndpoint]}]).
205+
EtcdEndpoints = [rabbit_misc:format("~s:~b", [EtcdHost, EtcdClientPort])],
206+
Config1 = rabbit_ct_helpers:set_config(
207+
Config,
208+
[{etcd_pid, EtcdPid},
209+
{etcd_endpoints, EtcdEndpoints}]),
210+
211+
#{level := Level} = logger:get_primary_config(),
212+
logger:set_primary_config(level, critical),
213+
try
214+
wait_for_etcd(EtcdEndpoints),
215+
Config1
216+
catch
217+
exit:{test_case_failed, _} ->
218+
stop_etcd(Config1),
219+
{skip, "Failed to start etcd"}
220+
after
221+
logger:set_primary_config(level, Level)
222+
end.
223+
224+
do_start_etcd(Cmd) ->
225+
case rabbit_ct_helpers:exec(Cmd) of
226+
{ok, Stdout} ->
227+
ct:pal("etcd daemon exited:~n~s", [Stdout]);
228+
{error, Reason, Stdout} ->
229+
ct:pal(
230+
"etcd daemon exited with error ~0p:~n~s",
231+
[Reason, Stdout])
232+
end.
233+
234+
wait_for_etcd(EtcdEndpoints) ->
235+
application:ensure_all_started(eetcd),
236+
237+
Timeout = 60000,
238+
rabbit_ct_helpers:await_condition(
239+
fun() ->
240+
case eetcd:open(test, EtcdEndpoints) of
241+
{ok, _Pid} -> true;
242+
_ -> false
243+
end
244+
end, Timeout),
245+
246+
Condition1 = fun() -> 1 =:= length(eetcd_conn_sup:info()) end,
247+
try
248+
rabbit_ct_helpers:await_condition(Condition1, Timeout)
249+
after
250+
eetcd:close(test)
251+
end,
252+
Condition2 = fun() -> 0 =:= length(eetcd_conn_sup:info()) end,
253+
rabbit_ct_helpers:await_condition(Condition2, Timeout).
212254

213255
stop_etcd(Config) ->
214256
case rabbit_ct_helpers:get_config(Config, etcd_pid) of
@@ -226,24 +268,6 @@ stop_etcd(Config) ->
226268
%% Test cases
227269
%%
228270

229-
etcd_connection_sanity_check_test(Config) ->
230-
application:ensure_all_started(eetcd),
231-
Endpoints = ?config(etcd_endpoints, Config),
232-
?assertMatch({ok, _Pid}, eetcd:open(test, Endpoints)),
233-
234-
Condition1 = fun() ->
235-
1 =:= length(eetcd_conn_sup:info())
236-
end,
237-
try
238-
rabbit_ct_helpers:await_condition(Condition1, 60000)
239-
after
240-
eetcd:close(test)
241-
end,
242-
Condition2 = fun() ->
243-
0 =:= length(eetcd_conn_sup:info())
244-
end,
245-
rabbit_ct_helpers:await_condition(Condition2, 60000).
246-
247271
init_opens_a_connection_test(Config) ->
248272
Endpoints = ?config(etcd_endpoints, Config),
249273
{ok, Pid} = start_client(Endpoints),

0 commit comments

Comments
 (0)