Skip to content

Commit 6cc03b0

Browse files
committed
Tests for rabbitmq-queues leader_health_check command
1 parent c26edbe commit 6cc03b0

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

deps/rabbit/test/quorum_queue_SUITE.erl

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ all_tests() ->
192192
priority_queue_2_1_ratio,
193193
requeue_multiple_true,
194194
requeue_multiple_false,
195-
subscribe_from_each
195+
subscribe_from_each,
196+
leader_health_check
196197
].
197198

198199
memory_tests() ->
@@ -4145,6 +4146,23 @@ amqpl_headers(Config) ->
41454146
ok = amqp_channel:cast(Ch, #'basic.ack'{delivery_tag = DeliveryTag,
41464147
multiple = true}).
41474148

4149+
leader_health_check(Config) ->
4150+
[Server | _] = _Servers = rabbit_ct_broker_helpers:get_node_configs(Config, nodename),
4151+
Ch = rabbit_ct_client_helpers:open_channel(Config, Server),
4152+
[?assertEqual({'queue.declare_ok', Q, 0, 0},
4153+
declare(Ch, Q, [{<<"x-queue-type">>, longstr, <<"quorum">>}]))
4154+
|| Q <- [<<"Q.1">>, <<"Q.2">>, <<"Q.3">>]],
4155+
?assertEqual([], rabbit_ct_broker_helpers:rpc(Config, 0, rabbit_quorum_queue, leader_health_check,
4156+
[<<".*">>, <<"/">>])),
4157+
?assertEqual([], rabbit_ct_broker_helpers:rpc(Config, 0, rabbit_quorum_queue, leader_health_check,
4158+
[<<"Q.*">>, <<"/">>])),
4159+
?assertEqual([], rabbit_ct_broker_helpers:rpc(Config, 0, rabbit_quorum_queue, leader_health_check,
4160+
[<<"Q.1">>, <<"/">>])),
4161+
?assertEqual([], rabbit_ct_broker_helpers:rpc(Config, 0, rabbit_quorum_queue, leader_health_check,
4162+
[<<"Q.2">>, <<"/">>])),
4163+
?assertEqual([], rabbit_ct_broker_helpers:rpc(Config, 0, rabbit_quorum_queue, leader_health_check,
4164+
[<<"Q.3">>, <<"/">>])).
4165+
41484166
leader_locator_client_local(Config) ->
41494167
[Server1 | _] = Servers = rabbit_ct_broker_helpers:get_node_configs(Config, nodename),
41504168
Q = ?config(queue_name, Config),
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
## This Source Code Form is subject to the terms of the Mozilla Public
2+
## License, v. 2.0. If a copy of the MPL was not distributed with this
3+
## file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
##
5+
## Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
6+
7+
defmodule RabbitMQ.CLI.Queues.Commands.LeaderHealthCheckCommandTest do
8+
use ExUnit.Case, async: false
9+
import TestHelper
10+
11+
@command RabbitMQ.CLI.Queues.Commands.LeaderHealthCheckCommand
12+
13+
setup_all do
14+
RabbitMQ.CLI.Core.Distribution.start()
15+
16+
:ok
17+
end
18+
19+
setup context do
20+
{:ok,
21+
opts: %{
22+
node: get_rabbit_hostname(),
23+
timeout: context[:test_timeout] || 30000
24+
}}
25+
end
26+
27+
test "validate: treats no arguments as a failure" do
28+
assert @command.validate([], %{}) == {:validation_failure, :not_enough_args}
29+
end
30+
31+
test "validate: accepts a single positional argument" do
32+
assert @command.validate(["quorum.queue.*"], %{}) == :ok
33+
end
34+
35+
test "validate: when two or more arguments are provided, returns a failure" do
36+
assert @command.validate(["quorum.queue.*", "one-extra-arg"], %{}) ==
37+
{:validation_failure, :too_many_args}
38+
39+
assert @command.validate(["quorum.queue.*", "extra-arg", "another-extra-arg"], %{}) ==
40+
{:validation_failure, :too_many_args}
41+
end
42+
43+
@tag test_timeout: 3000
44+
test "run: targeting an unreachable node throws a badrpc" do
45+
assert match?(
46+
{:badrpc, _},
47+
@command.run(
48+
["quorum.queue.*"],
49+
%{node: :jake@thedog, vhost: "/", timeout: 200}
50+
)
51+
)
52+
end
53+
end

0 commit comments

Comments
 (0)