Skip to content

Commit 1f52406

Browse files
author
Daniil Fedotov
committed
Test that list_queues return stopped state for queues taken down by vhost supervisors
1 parent fab1dcd commit 1f52406

File tree

2 files changed

+33
-39
lines changed

2 files changed

+33
-39
lines changed

test/rabbitmqctl_integration_SUITE.erl

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
-export([list_queues_local/1
3232
,list_queues_offline/1
3333
,list_queues_online/1
34+
,list_queues_stopped/1
3435
]).
3536

3637
all() ->
@@ -44,6 +45,7 @@ groups() ->
4445
[list_queues_local
4546
,list_queues_online
4647
,list_queues_offline
48+
,list_queues_stopped
4749
]}
4850
].
4951

@@ -96,13 +98,19 @@ end_per_group(list_queues, Config0) ->
9698
rabbit_ct_helpers:run_steps(Config1,
9799
rabbit_ct_client_helpers:teardown_steps() ++
98100
rabbit_ct_broker_helpers:teardown_steps());
99-
end_per_group(global_parameters, Config) ->
100-
rabbit_ct_helpers:run_teardown_steps(Config,
101-
rabbit_ct_client_helpers:teardown_steps() ++
102-
rabbit_ct_broker_helpers:teardown_steps());
103101
end_per_group(_, Config) ->
104102
Config.
105103

104+
init_per_testcase(list_queues_stopped, Config0) ->
105+
%% Start node 3 to crash it's queues
106+
rabbit_ct_broker_helpers:start_node(Config0, 2),
107+
%% Make vhost "down" on nodes 2 and 3
108+
rabbit_ct_broker_helpers:force_vhost_failure(Config0, 1, <<"/">>),
109+
rabbit_ct_broker_helpers:force_vhost_failure(Config0, 2, <<"/">>),
110+
111+
rabbit_ct_broker_helpers:stop_node(Config0, 2),
112+
rabbit_ct_helpers:testcase_started(Config0, list_queues_stopped);
113+
106114
init_per_testcase(Testcase, Config0) ->
107115
rabbit_ct_helpers:testcase_started(Config0, Testcase).
108116

@@ -134,6 +142,23 @@ list_queues_offline(Config) ->
134142
assert_ctl_queues(Config, 1, ["--offline"], OfflineQueues),
135143
ok.
136144

145+
list_queues_stopped(Config) ->
146+
Node1Queues = lists:sort(lists:nth(1, ?config(per_node_queues, Config))),
147+
Node2Queues = lists:sort(lists:nth(2, ?config(per_node_queues, Config))),
148+
Node3Queues = lists:sort(lists:nth(3, ?config(per_node_queues, Config))),
149+
150+
%% All queues are listed
151+
ListedQueues =
152+
[ {Name, State}
153+
|| [Name, State] <- rabbit_ct_broker_helpers:rabbitmqctl_list(
154+
Config, 0, ["list_queues", "name", "state"]) ],
155+
156+
[ <<"running">> = proplists:get_value(Q, ListedQueues) || Q <- Node1Queues ],
157+
%% Node is running. Vhost is down
158+
[ <<"stopped">> = proplists:get_value(Q, ListedQueues) || Q <- Node2Queues ],
159+
%% Node is not running. Vhost is down
160+
[ <<"down">> = proplists:get_value(Q, ListedQueues) || Q <- Node3Queues ].
161+
137162
%%----------------------------------------------------------------------------
138163
%% Helpers
139164
%%----------------------------------------------------------------------------

test/vhost_SUITE.erl

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ vhost_failure_forces_connection_closure(Config) ->
161161
[_Conn2] = open_connections(Config, [{0, VHost2}]),
162162
?assertEqual(1, count_connections_in(Config, VHost2)),
163163

164-
force_vhost_failure(Config, VHost2),
164+
rabbit_ct_broker_helpers:force_vhost_failure(Config, VHost2),
165165
timer:sleep(200),
166166
?assertEqual(0, count_connections_in(Config, VHost2)),
167167

@@ -181,7 +181,7 @@ dead_vhost_connection_refused(Config) ->
181181
?assertEqual(0, count_connections_in(Config, VHost1)),
182182
?assertEqual(0, count_connections_in(Config, VHost2)),
183183

184-
force_vhost_failure(Config, VHost2),
184+
rabbit_ct_broker_helpers:force_vhost_failure(Config, VHost2),
185185
timer:sleep(200),
186186

187187
[_Conn1] = open_connections(Config, [{0, VHost1}]),
@@ -213,7 +213,7 @@ vhost_failure_forces_connection_closure_on_failure_node(Config) ->
213213
[_Conn21] = open_connections(Config, [{1, VHost2}]),
214214
?assertEqual(2, count_connections_in(Config, VHost2)),
215215

216-
force_vhost_failure(Config, 0, VHost2),
216+
rabbit_ct_broker_helpers:force_vhost_failure(Config, 0, VHost2),
217217
timer:sleep(200),
218218
%% Vhost2 connection on node 1 is still alive
219219
?assertEqual(1, count_connections_in(Config, VHost2)),
@@ -236,7 +236,7 @@ dead_vhost_connection_refused_on_failure_node(Config) ->
236236
?assertEqual(0, count_connections_in(Config, VHost1)),
237237
?assertEqual(0, count_connections_in(Config, VHost2)),
238238

239-
force_vhost_failure(Config, 0, VHost2),
239+
rabbit_ct_broker_helpers:force_vhost_failure(Config, 0, VHost2),
240240
timer:sleep(200),
241241
%% Can open connections to vhost1 on node 0 and 1
242242
[_Conn10] = open_connections(Config, [{0, VHost1}]),
@@ -257,37 +257,6 @@ dead_vhost_connection_refused_on_failure_node(Config) ->
257257
rabbit_ct_broker_helpers:delete_vhost(Config, VHost2),
258258
rabbit_ct_broker_helpers:delete_vhost(Config, VHost1).
259259

260-
force_vhost_failure(Config, VHost) -> force_vhost_failure(Config, 0, VHost).
261-
262-
force_vhost_failure(Config, Node, VHost) ->
263-
force_vhost_failure(Config, Node, VHost, 10).
264-
265-
force_vhost_failure(_Config, _Node, VHost, 0) ->
266-
error({failed_to_force_vhost_failure, no_more_attempts_left, VHost});
267-
force_vhost_failure(Config, Node, VHost, Attempts) ->
268-
MessageStorePid = get_message_store_pid(Config, VHost),
269-
rabbit_ct_broker_helpers:rpc(Config, Node,
270-
erlang, exit,
271-
[MessageStorePid, force_vhost_failure]),
272-
%% Give it a time to fail
273-
timer:sleep(200),
274-
case rabbit_ct_broker_helpers:rpc(Config, 0,
275-
rabbit_vhost_sup_sup, is_vhost_alive,
276-
[VHost]) of
277-
true -> force_vhost_failure(Config, Node, VHost, Attempts - 1);
278-
false -> ok
279-
end.
280-
281-
get_message_store_pid(Config, VHost) ->
282-
{ok, VHostSup} = rabbit_ct_broker_helpers:rpc(Config, 0,
283-
rabbit_vhost_sup_sup, vhost_sup, [VHost]),
284-
Children = rabbit_ct_broker_helpers:rpc(Config, 0,
285-
supervisor, which_children,
286-
[VHostSup]),
287-
[MsgStorePid] = [Pid || {Name, Pid, _, _} <- Children,
288-
Name == msg_store_persistent],
289-
MsgStorePid.
290-
291260
cluster_vhost_deletion_forces_connection_closure(Config) ->
292261
VHost1 = <<"vhost1">>,
293262
VHost2 = <<"vhost2">>,

0 commit comments

Comments
 (0)