Skip to content

Commit a13f5d6

Browse files
committed
Add tests for QQ grow to target quorum cluster size command
1 parent 662bbd5 commit a13f5d6

File tree

2 files changed

+100
-3
lines changed

2 files changed

+100
-3
lines changed

deps/rabbit/test/quorum_queue_SUITE.erl

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ groups() ->
110110
node_removal_is_not_quorum_critical,
111111
select_nodes_with_least_replicas,
112112
select_nodes_with_least_replicas_node_down,
113-
subscribe_from_each
113+
subscribe_from_each,
114+
grow_queue
114115

115116

116117
]},
@@ -1536,6 +1537,77 @@ subscribe_from_each(Config) ->
15361537

15371538
ok.
15381539

1540+
grow_queue(Config) ->
1541+
[Server0, Server1, _Server2, _Server3, _Server4] =
1542+
rabbit_ct_broker_helpers:get_node_configs(Config, nodename),
1543+
1544+
Ch = rabbit_ct_client_helpers:open_channel(Config, Server0),
1545+
QQ = ?config(queue_name, Config),
1546+
AQ = ?config(alt_queue_name, Config),
1547+
?assertEqual({'queue.declare_ok', QQ, 0, 0},
1548+
declare(Ch, QQ, [{<<"x-queue-type">>, longstr, <<"quorum">>},
1549+
{<<"x-quorum-initial-group-size">>, long, 5}])),
1550+
?assertEqual({'queue.declare_ok', AQ, 0, 0},
1551+
declare(Ch, AQ, [{<<"x-queue-type">>, longstr, <<"quorum">>},
1552+
{<<"x-quorum-initial-group-size">>, long, 5}])),
1553+
1554+
QQs = [QQ, AQ],
1555+
MsgCount = 3,
1556+
1557+
[begin
1558+
RaName = ra_name(Q),
1559+
rabbit_ct_client_helpers:publish(Ch, Q, MsgCount),
1560+
wait_for_messages_ready([Server0], RaName, MsgCount),
1561+
{ok, Q0} = rpc:call(Server0, rabbit_amqqueue, lookup, [Q, <<"/">>]),
1562+
#{nodes := Nodes0} = amqqueue:get_type_state(Q0),
1563+
?assertEqual(5, length(Nodes0))
1564+
end || Q <- QQs],
1565+
1566+
rabbit_ct_broker_helpers:rpc(Config, 0, rabbit_quorum_queue,
1567+
force_all_queues_shrink_member_to_current_member, []),
1568+
1569+
TargetClusterSize_1 = 1,
1570+
assert_grown_queues(QQs, Server0, TargetClusterSize_1, MsgCount),
1571+
1572+
%% grow queues to node 'Server1'
1573+
TargetClusterSize_2 = 2,
1574+
rpc:call(Server0, rabbit_quorum_queue, grow, [Server1, <<"/">>, <<".*">>, all]),
1575+
assert_grown_queues(QQs, Server0, TargetClusterSize_2, MsgCount),
1576+
1577+
%% grow queues to quorum cluster size '2' has no effect
1578+
rpc:call(Server0, rabbit_quorum_queue, grow, [TargetClusterSize_2, <<"/">>, <<".*">>, all]),
1579+
assert_grown_queues(QQs, Server0, TargetClusterSize_2, MsgCount),
1580+
1581+
%% grow queues to quorum cluster size '3'
1582+
TargetClusterSize_3 = 3,
1583+
rpc:call(Server0, rabbit_quorum_queue, grow, [TargetClusterSize_3, <<"/">>, <<".*">>, all]),
1584+
assert_grown_queues(QQs, Server0, TargetClusterSize_3, MsgCount),
1585+
1586+
%% grow queues to quorum cluster size '5'
1587+
TargetClusterSize_5 = 5,
1588+
rpc:call(Server0, rabbit_quorum_queue, grow, [TargetClusterSize_5, <<"/">>, <<".*">>, all]),
1589+
assert_grown_queues(QQs, Server0, TargetClusterSize_5, MsgCount),
1590+
1591+
%% shrink all queues again
1592+
rabbit_ct_broker_helpers:rpc(Config, 0, rabbit_quorum_queue,
1593+
force_all_queues_shrink_member_to_current_member, []),
1594+
1595+
assert_grown_queues(QQs, Server0, TargetClusterSize_1, MsgCount),
1596+
1597+
%% grow queues to quorum cluster size > '5' (limit = 5).
1598+
TargetClusterSize_10 = 10,
1599+
rpc:call(Server0, rabbit_quorum_queue, grow, [TargetClusterSize_10, <<"/">>, <<".*">>, all]),
1600+
assert_grown_queues(QQs, Server0, TargetClusterSize_5, MsgCount).
1601+
1602+
assert_grown_queues(Qs, Node, TargetClusterSize, MsgCount) ->
1603+
[begin
1604+
RaName = ra_name(Q),
1605+
wait_for_messages_ready([Node], RaName, MsgCount),
1606+
{ok, Q0} = rpc:call(Node, rabbit_amqqueue, lookup, [Q, <<"/">>]),
1607+
#{nodes := Nodes0} = amqqueue:get_type_state(Q0),
1608+
?assertEqual(TargetClusterSize, length(Nodes0))
1609+
end || Q <- Qs].
1610+
15391611
gh_12635(Config) ->
15401612
% https://github.com/rabbitmq/rabbitmq-server/issues/12635
15411613
[Server0, _Server1, Server2] =

deps/rabbitmq_cli/test/queues/grow_command_test.exs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,37 @@ defmodule RabbitMQ.CLI.Queues.Commands.GrowCommandTest do
8282
{:validation_failure, "voter status 'banana' is not recognised."}
8383
end
8484

85+
test "validate: when target quorum cluster size greater than zero, returns a success" do
86+
assert @command.validate([7, "all"], %{membership: "voter"}) == :ok
87+
end
88+
89+
test "validate: when target quorum cluster size is zero, returns failure" do
90+
assert @command.validate([0, "all"], %{membership: "voter"}) ==
91+
{:validation_failure, "target quorum cluster size '0' must be greater than 0."}
92+
end
93+
94+
test "validate: when target quorum cluster size is less than zero, returns failure" do
95+
assert @command.validate([-1, "all"], %{membership: "voter"}) ==
96+
{:validation_failure, "target quorum cluster size '-1' must be greater than 0."}
97+
end
98+
99+
@tag test_timeout: 3000
100+
test "run: targeting an unreachable node throws a badrpc when growing to a target node", context do
101+
assert match?(
102+
{:badrpc, _},
103+
@command.run(
104+
["target@node", "all"],
105+
Map.merge(context[:opts], %{node: :jake@thedog})
106+
)
107+
)
108+
end
109+
85110
@tag test_timeout: 3000
86-
test "run: targeting an unreachable node throws a badrpc", context do
111+
test "run: targeting an unreachable node throws a badrpc when growing to a target quorum cluster size", context do
87112
assert match?(
88113
{:badrpc, _},
89114
@command.run(
90-
["quorum-queue-a", "all"],
115+
[5, "all"],
91116
Map.merge(context[:opts], %{node: :jake@thedog})
92117
)
93118
)

0 commit comments

Comments
 (0)