Skip to content

Commit c4ec86b

Browse files
dcorbachomergify[bot]
authored andcommitted
Shovel tests: extract common test cases to all protocols into a generic test suite
(cherry picked from commit 28f9720)
1 parent a843030 commit c4ec86b

File tree

3 files changed

+215
-31
lines changed

3 files changed

+215
-31
lines changed

deps/rabbitmq_shovel/test/amqp091_dynamic_SUITE.erl

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ all() ->
3030
groups() ->
3131
[
3232
{core_tests, [], [
33-
simple,
3433
set_properties_using_proplist,
3534
set_properties_using_map,
3635
set_empty_properties_using_proplist,
@@ -118,21 +117,6 @@ end_per_testcase(Testcase, Config) ->
118117
%% -------------------------------------------------------------------
119118
%% Testcases.
120119
%% -------------------------------------------------------------------
121-
122-
simple(Config) ->
123-
Name = <<"test">>,
124-
with_ch(Config,
125-
fun (Ch) ->
126-
shovel_test_utils:set_param(
127-
Config,
128-
Name, [{<<"src-queue">>, <<"src">>},
129-
{<<"dest-queue">>, <<"dest">>}]),
130-
publish_expect(Ch, <<>>, <<"src">>, <<"dest">>, <<"hello">>),
131-
Status = rabbit_ct_broker_helpers:rpc(Config, 0, rabbit_shovel_status, lookup, [{<<"/">>, Name}]),
132-
?assertMatch([_|_], Status),
133-
?assertMatch(#{metrics := #{forwarded := 1}}, maps:from_list(Status))
134-
end).
135-
136120
quorum_queues(Config) ->
137121
with_ch(Config,
138122
fun (Ch) ->

deps/rabbitmq_shovel/test/local_dynamic_SUITE.erl

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ groups() ->
3232
[
3333
{tests, [], [
3434
local_to_local_opt_headers,
35-
local_to_local_queue_dest,
3635
local_to_local_original_dest,
3736
local_to_local_exchange_dest,
3837
local_to_local_missing_exchange_dest,
@@ -168,20 +167,6 @@ local_to_local_opt_headers(Config) ->
168167
amqp10_msg:message_annotations(Msg))
169168
end).
170169

171-
local_to_local_queue_dest(Config) ->
172-
Src = ?config(srcq, Config),
173-
Dest = ?config(destq, Config),
174-
with_amqp10_session(Config,
175-
fun (Sess) ->
176-
shovel_test_utils:set_param(Config, ?PARAM,
177-
[{<<"src-protocol">>, <<"local">>},
178-
{<<"src-queue">>, Src},
179-
{<<"dest-protocol">>, <<"local">>},
180-
{<<"dest-queue">>, Dest}
181-
]),
182-
_ = amqp10_publish_expect(Sess, Src, Dest, <<"hello">>, 1)
183-
end).
184-
185170
local_to_local_original_dest(Config) ->
186171
%% Publish with the original routing keys, but use a different vhost
187172
%% to avoid a loop (this is a single-node test).
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
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-2025 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
6+
%%
7+
8+
-module(shovel_dynamic_SUITE).
9+
%% Common test cases to all protocols
10+
11+
-include_lib("common_test/include/ct.hrl").
12+
-include_lib("eunit/include/eunit.hrl").
13+
-include_lib("rabbitmq_ct_helpers/include/rabbit_assert.hrl").
14+
15+
-compile(export_all).
16+
17+
-import(shovel_test_utils, [set_param/3,
18+
with_amqp10_session/2,
19+
amqp10_publish_expect/5]).
20+
21+
-define(PARAM, <<"test">>).
22+
23+
all() ->
24+
[
25+
{group, amqp091},
26+
{group, amqp10},
27+
{group, local},
28+
{group, amqp091_to_amqp10},
29+
{group, amqp091_to_local},
30+
{group, amqp10_to_amqp091},
31+
{group, amqp10_to_local},
32+
{group, local_to_amqp091},
33+
{group, local_to_amqp10}
34+
].
35+
36+
groups() ->
37+
[
38+
{amqp091, [], tests()},
39+
{amqp10, [], tests()},
40+
{local, [], tests()},
41+
{amqp091_to_amqp10, [], tests()},
42+
{amqp091_to_local, [], tests()},
43+
{amqp10_to_amqp091, [], tests()},
44+
{amqp10_to_local, [], tests()},
45+
{local_to_amqp091, [], tests()},
46+
{local_to_amqp10, [], tests()}
47+
].
48+
49+
tests() ->
50+
[
51+
simple
52+
].
53+
54+
%% -------------------------------------------------------------------
55+
%% Testsuite setup/teardown.
56+
%% -------------------------------------------------------------------
57+
58+
init_per_suite(Config0) ->
59+
{ok, _} = application:ensure_all_started(amqp10_client),
60+
rabbit_ct_helpers:log_environment(),
61+
Config1 = rabbit_ct_helpers:set_config(Config0, [
62+
{rmq_nodename_suffix, ?MODULE},
63+
{ignored_crashes, [
64+
"server_initiated_close,404",
65+
"writer,send_failed,closed",
66+
"source_queue_down",
67+
"dest_queue_down"
68+
]}
69+
]),
70+
rabbit_ct_helpers:run_setup_steps(
71+
Config1,
72+
rabbit_ct_broker_helpers:setup_steps() ++
73+
rabbit_ct_client_helpers:setup_steps()).
74+
75+
end_per_suite(Config) ->
76+
application:stop(amqp10_client),
77+
rabbit_ct_helpers:run_teardown_steps(Config,
78+
rabbit_ct_client_helpers:teardown_steps() ++
79+
rabbit_ct_broker_helpers:teardown_steps()).
80+
81+
init_per_group(amqp091, Config) ->
82+
rabbit_ct_helpers:set_config(
83+
Config,
84+
[
85+
{src_protocol, <<"amqp091">>},
86+
{dest_protocol, <<"amqp091">>},
87+
{src_address, <<"src-queue">>},
88+
{dest_address, <<"dest-queue">>}
89+
]);
90+
init_per_group(amqp10, Config) ->
91+
rabbit_ct_helpers:set_config(
92+
Config,
93+
[
94+
{src_protocol, <<"amqp10">>},
95+
{dest_protocol, <<"amqp10">>},
96+
{src_address, <<"src-address">>},
97+
{dest_address, <<"dest-address">>}
98+
]);
99+
init_per_group(local, Config0) ->
100+
Config = rabbit_ct_helpers:set_config(
101+
Config0,
102+
[
103+
{src_protocol, <<"local">>},
104+
{dest_protocol, <<"local">>},
105+
{src_address, <<"src-queue">>},
106+
{dest_address, <<"dest-queue">>}
107+
]),
108+
maybe_skip_local_protocol(Config);
109+
init_per_group(amqp091_to_amqp10, Config) ->
110+
rabbit_ct_helpers:set_config(
111+
Config,
112+
[
113+
{src_protocol, <<"amqp091">>},
114+
{dest_protocol, <<"amqp10">>},
115+
{src_address, <<"src-queue">>},
116+
{dest_address, <<"dest-address">>}
117+
]);
118+
init_per_group(amqp091_to_local, Config0) ->
119+
Config = rabbit_ct_helpers:set_config(
120+
Config0,
121+
[
122+
{src_protocol, <<"amqp091">>},
123+
{dest_protocol, <<"local">>},
124+
{src_address, <<"src-queue">>},
125+
{dest_address, <<"dest-queue">>}
126+
]),
127+
maybe_skip_local_protocol(Config);
128+
init_per_group(amqp10_to_amqp091, Config) ->
129+
rabbit_ct_helpers:set_config(
130+
Config,
131+
[
132+
{src_protocol, <<"amqp10">>},
133+
{dest_protocol, <<"amqp091">>},
134+
{src_address, <<"src-address">>},
135+
{dest_address, <<"dest-queue">>}
136+
]);
137+
init_per_group(amqp10_to_local, Config0) ->
138+
Config = rabbit_ct_helpers:set_config(
139+
Config0,
140+
[
141+
{src_protocol, <<"amqp10">>},
142+
{dest_protocol, <<"local">>},
143+
{src_address, <<"src-address">>},
144+
{dest_address, <<"dest-queue">>}
145+
]),
146+
maybe_skip_local_protocol(Config);
147+
init_per_group(local_to_amqp091, Config0) ->
148+
Config = rabbit_ct_helpers:set_config(
149+
Config0,
150+
[
151+
{src_protocol, <<"local">>},
152+
{dest_protocol, <<"amqp091">>},
153+
{src_address, <<"src-queue">>},
154+
{dest_address, <<"dest-queue">>}
155+
]),
156+
maybe_skip_local_protocol(Config);
157+
init_per_group(local_to_amqp10, Config0) ->
158+
Config = rabbit_ct_helpers:set_config(
159+
Config0,
160+
[
161+
{src_protocol, <<"local">>},
162+
{dest_protocol, <<"amqp10">>},
163+
{src_address, <<"src-queue">>},
164+
{dest_address, <<"dest-address">>}
165+
]),
166+
maybe_skip_local_protocol(Config).
167+
168+
end_per_group(_, Config) ->
169+
Config.
170+
171+
init_per_testcase(Testcase, Config0) ->
172+
SrcQ = list_to_binary(atom_to_list(Testcase) ++ "_src"),
173+
DestQ = list_to_binary(atom_to_list(Testcase) ++ "_dest"),
174+
ShovelArgs = [{<<"src-protocol">>, ?config(src_protocol, Config0)},
175+
{<<"dest-protocol">>, ?config(dest_protocol, Config0)},
176+
{?config(src_address, Config0), SrcQ},
177+
{?config(dest_address, Config0), DestQ}],
178+
Config = rabbit_ct_helpers:set_config(
179+
Config0,
180+
[{srcq, SrcQ}, {destq, DestQ}, {shovel_args, ShovelArgs}]),
181+
rabbit_ct_helpers:testcase_started(Config, Testcase).
182+
183+
end_per_testcase(Testcase, Config) ->
184+
shovel_test_utils:clear_param(Config, ?PARAM),
185+
rabbit_ct_broker_helpers:rpc(Config, 0, shovel_test_utils, delete_all_queues, []),
186+
rabbit_ct_helpers:testcase_finished(Config, Testcase).
187+
188+
%% -------------------------------------------------------------------
189+
%% Testcases.
190+
%% -------------------------------------------------------------------
191+
simple(Config) ->
192+
Name = <<"test">>,
193+
Src = ?config(srcq, Config),
194+
Dest = ?config(destq, Config),
195+
with_amqp10_session(
196+
Config,
197+
fun (Sess) ->
198+
set_param(Config, Name, ?config(shovel_args, Config)),
199+
amqp10_publish_expect(Sess, Src, Dest, <<"hello">>, 1),
200+
Status = rabbit_ct_broker_helpers:rpc(Config, 0, rabbit_shovel_status, lookup, [{<<"/">>, Name}]),
201+
?assertMatch([_|_], Status),
202+
?assertMatch(#{metrics := #{forwarded := 1}}, maps:from_list(Status))
203+
end).
204+
205+
206+
%%----------------------------------------------------------------------------
207+
maybe_skip_local_protocol(Config) ->
208+
[Node] = rabbit_ct_broker_helpers:get_node_configs(Config, nodename),
209+
case rabbit_ct_broker_helpers:enable_feature_flag(
210+
Config, [Node], 'rabbitmq_4.0.0') of
211+
ok ->
212+
Config;
213+
_ ->
214+
{skip, "This group requires rabbitmq_4.0.0 feature flag"}
215+
end.

0 commit comments

Comments
 (0)