Skip to content

Commit 2883962

Browse files
authored
Merge pull request #14310 from rabbitmq/fix-test-flakes-2025Q2
Collection of test fixes (2025Q2, batch 2)
2 parents 04815c5 + 0a5024b commit 2883962

26 files changed

+284
-141
lines changed

.github/workflows/test-make-target.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,6 @@ jobs:
143143
name: CT logs (${{ inputs.plugin }} ${{ inputs.make_target }} OTP-${{ inputs.erlang_version }} ${{ inputs.metadata_store }}${{ inputs.mixed_clusters && ' mixed' || '' }})
144144
path: |
145145
logs/
146+
deps/rabbitmq_cli/logs/
146147
# !logs/**/log_private
147148
if-no-files-found: ignore

deps/rabbit/src/rabbit_vhosts.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ start_processes_for_all(Nodes) ->
127127

128128
-spec start_processes_for_all() -> 'ok'.
129129
start_processes_for_all() ->
130-
start_processes_for_all(rabbit_nodes:list_reachable()).
130+
start_processes_for_all(rabbit_nodes:list_running()).
131131

132132
%% Same as rabbit_vhost_sup_sup:start_on_all_nodes/0.
133133
-spec start_on_all_nodes(vhost:name(), [node()]) -> 'ok'.

deps/rabbit/test/amqp_client_SUITE.erl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1867,6 +1867,11 @@ link_target_queue_deleted(QType, Config) ->
18671867
ok = amqp10_client:send_msg(Sender, amqp10_msg:new(DTag1, <<"m1">>, false)),
18681868
ok = wait_for_accepted(DTag1),
18691869

1870+
%% Load test module on the broker: we reference an anonymous function
1871+
%% from it during the configuration of meck.
1872+
[_ | _] = rabbit_ct_broker_helpers:rpc(
1873+
Config, ?MODULE, module_info, []),
1874+
18701875
%% Mock delivery to the target queue to do nothing.
18711876
rabbit_ct_broker_helpers:setup_meck(Config, [?MODULE]),
18721877
Mod = rabbit_queue_type,
@@ -1927,6 +1932,11 @@ target_queues_deleted_accepted(Config) ->
19271932
ok = amqp10_client:send_msg(Sender, amqp10_msg:new(DTag1, <<"m1">>, false)),
19281933
ok = wait_for_accepted(DTag1),
19291934

1935+
%% Load test module on the broker: we reference an anonymous function
1936+
%% from it during the configuration of meck.
1937+
[_ | _] = rabbit_ct_broker_helpers:rpc(
1938+
Config, ?MODULE, module_info, []),
1939+
19301940
%% Mock to deliver only to q1.
19311941
rabbit_ct_broker_helpers:setup_meck(Config, [?MODULE]),
19321942
Mod = rabbit_queue_type,
@@ -4073,7 +4083,7 @@ list_connections(Config) ->
40734083
end,
40744084

40754085
{ok, StdOut0} = rabbit_ct_broker_helpers:rabbitmqctl(Config, 0, ["list_connections", "--silent", "protocol"]),
4076-
Protocols0 = re:split(StdOut0, <<"\n">>, [trim]),
4086+
Protocols0 = re:split(string:trim(StdOut0), <<"\n">>, [trim]),
40774087
%% Remove any whitespaces.
40784088
Protocols1 = [binary:replace(Subject, <<" ">>, <<>>, [global]) || Subject <- Protocols0],
40794089
Protocols = lists:sort(Protocols1),
@@ -4726,6 +4736,11 @@ idle_time_out_on_server(Config) ->
47264736
after 30000 -> ct:fail({missing_event, ?LINE})
47274737
end,
47284738

4739+
%% Load test module on the broker: we reference an anonymous function
4740+
%% from it during the configuration of meck.
4741+
[_ | _] = rabbit_ct_broker_helpers:rpc(
4742+
Config, ?MODULE, module_info, []),
4743+
47294744
%% Mock the server socket to not have received any bytes.
47304745
rabbit_ct_broker_helpers:setup_meck(Config),
47314746
ok = rpc(Config, meck, new, [Mod, [no_link, passthrough]]),

deps/rabbit/test/amqp_filter_sql_SUITE.erl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
flush/1,
2727
wait_for_credit/1,
2828
wait_for_accepts/1,
29+
send_message/2,
2930
send_messages/3,
3031
detach_link_sync/1,
3132
end_session_sync/1,
@@ -98,10 +99,10 @@ multiple_sections(Config) ->
9899
To = rabbitmq_amqp_address:exchange(<<"some exchange">>, <<"routing key">>),
99100
ReplyTo = rabbitmq_amqp_address:queue(<<"some queue">>),
100101

101-
ok = amqp10_client:send_msg(
102+
ok = send_message(
102103
Sender,
103104
amqp10_msg:new(<<"t1">>, <<"m1">>)),
104-
ok = amqp10_client:send_msg(
105+
ok = send_message(
105106
Sender,
106107
amqp10_msg:set_headers(
107108
#{priority => 200},
@@ -125,7 +126,7 @@ multiple_sections(Config) ->
125126
<<"k3">> => true,
126127
<<"k4">> => <<"hey👋"/utf8>>},
127128
amqp10_msg:new(<<"t2">>, <<"m2">>))))),
128-
ok = amqp10_client:send_msg(
129+
ok = send_message(
129130
Sender,
130131
amqp10_msg:set_properties(
131132
#{group_id => <<"my group ID">>},
@@ -222,13 +223,13 @@ filter_few_messages_from_many(Config) ->
222223
{ok, Sender} = amqp10_client:attach_sender_link(Session, <<"sender">>, Address),
223224
ok = wait_for_credit(Sender),
224225

225-
ok = amqp10_client:send_msg(
226+
ok = send_message(
226227
Sender,
227228
amqp10_msg:set_properties(
228229
#{group_id => <<"my group ID">>},
229230
amqp10_msg:new(<<"t1">>, <<"first msg">>))),
230231
ok = send_messages(Sender, 5000, false),
231-
ok = amqp10_client:send_msg(
232+
ok = send_message(
232233
Sender,
233234
amqp10_msg:set_properties(
234235
#{group_id => <<"my group ID">>},
@@ -278,7 +279,7 @@ filter_few_messages_from_many(Config) ->
278279

279280
%% We previously set drain=true for Receiver1
280281
ok = assert_credit_exhausted(Receiver1, ?LINE),
281-
ok = amqp10_client:send_msg(
282+
ok = send_message(
282283
Sender,
283284
amqp10_msg:set_properties(
284285
#{group_id => <<"my group ID">>},
@@ -328,7 +329,7 @@ sql_and_bloom_filter(Config) ->
328329
{ok, Sender} = amqp10_client:attach_sender_link(Session, <<"sender">>, Address),
329330
ok = wait_for_credit(Sender),
330331

331-
ok = amqp10_client:send_msg(
332+
ok = send_message(
332333
Sender,
333334
amqp10_msg:set_message_annotations(
334335
#{<<"x-stream-filter-value">> => <<"v1">>},

deps/rabbit/test/amqp_jms_SUITE.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ groups() ->
5252

5353
suite() ->
5454
[
55-
{timetrap, {minutes, 2}}
55+
{timetrap, {minutes, 5}}
5656
].
5757

5858
init_per_suite(Config) ->

deps/rabbit/test/amqp_utils.erl

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
flush/1,
1717
wait_for_credit/1,
1818
wait_for_accepts/1,
19+
send_message/2,
1920
send_messages/3, send_messages/4,
2021
detach_link_sync/1,
2122
end_session_sync/1,
@@ -87,18 +88,10 @@ wait_for_accepts(N) ->
8788
ct:fail({missing_accepted, N})
8889
end.
8990

90-
send_messages(Sender, Left, Settled) ->
91-
send_messages(Sender, Left, Settled, <<>>).
92-
93-
send_messages(_, 0, _, _) ->
94-
ok;
95-
send_messages(Sender, Left, Settled, BodySuffix) ->
96-
Bin = integer_to_binary(Left),
97-
Body = <<Bin/binary, BodySuffix/binary>>,
98-
Msg = amqp10_msg:new(Bin, Body, Settled),
91+
send_message(Sender, Msg) ->
9992
case amqp10_client:send_msg(Sender, Msg) of
10093
ok ->
101-
send_messages(Sender, Left - 1, Settled, BodySuffix);
94+
ok;
10295
{error, insufficient_credit} ->
10396
ok = wait_for_credit(Sender),
10497
%% The credited event we just processed could have been received some time ago,
@@ -110,9 +103,21 @@ send_messages(Sender, Left, Settled, BodySuffix) ->
110103
%% but do not process the credited event in our mailbox.
111104
%% So, we must be defensive here and assume that the next amqp10_client:send/2 call might return {error, insufficient_credit}
112105
%% again causing us then to really wait to receive a credited event (instead of just processing an old credited event).
113-
send_messages(Sender, Left, Settled, BodySuffix)
106+
send_message(Sender, Msg)
114107
end.
115108

109+
send_messages(Sender, Left, Settled) ->
110+
send_messages(Sender, Left, Settled, <<>>).
111+
112+
send_messages(_, 0, _, _) ->
113+
ok;
114+
send_messages(Sender, Left, Settled, BodySuffix) ->
115+
Bin = integer_to_binary(Left),
116+
Body = <<Bin/binary, BodySuffix/binary>>,
117+
Msg = amqp10_msg:new(Bin, Body, Settled),
118+
ok = send_message(Sender, Msg),
119+
send_messages(Sender, Left - 1, Settled, BodySuffix).
120+
116121
detach_link_sync(Link) ->
117122
ok = amqp10_client:detach_link(Link),
118123
ok = wait_for_link_detach(Link).

deps/rabbit/test/feature_flags_v2_SUITE.erl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ stop_slave_node(Node) ->
203203
persistent_term:erase({?MODULE, Node}),
204204

205205
ct:pal("- Stopping slave node `~ts`...", [Node]),
206-
_ = peer:stop(NodePid)
206+
Ret = catch peer:stop(NodePid),
207+
ct:pal(" Ret = ~0p", [Ret]),
208+
ok
207209
end.
208210

209211
connect_nodes([FirstNode | OtherNodes] = Nodes) ->

deps/rabbit/test/per_user_connection_channel_tracking_SUITE.erl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ single_node_user_connection_channel_tracking(Config) ->
130130
[Conn1] = open_connections(Config, [0]),
131131
[Chan1] = open_channels(Conn1, 1),
132132
?awaitMatch(1, count_connections_in(Config, Username), ?A_TOUT),
133-
[#tracked_connection{username = Username}] = connections_in(Config, Username),
133+
?awaitMatch([#tracked_connection{username = Username}], connections_in(Config, Username), ?A_TOUT),
134134
?awaitMatch(1, count_channels_in(Config, Username), ?A_TOUT),
135135
[#tracked_channel{username = Username}] = channels_in(Config, Username),
136136
?awaitMatch(true, is_process_alive(Conn1), ?A_TOUT),
@@ -147,7 +147,7 @@ single_node_user_connection_channel_tracking(Config) ->
147147
[Conn2] = open_connections(Config, [{0, Username2}]),
148148
Chans2 = [_|_] = open_channels(Conn2, 5),
149149
?awaitMatch(1, count_connections_in(Config, Username2), ?A_TOUT),
150-
[#tracked_connection{username = Username2}] = connections_in(Config, Username2),
150+
?awaitMatch([#tracked_connection{username = Username2}], connections_in(Config, Username2), ?A_TOUT),
151151
?awaitMatch(5, count_channels_in(Config, Username2), ?A_TOUT),
152152
?awaitMatch(1, tracked_user_connection_count(Config, Username2), ?A_TOUT),
153153
?awaitMatch(5, tracked_user_channel_count(Config, Username2), ?A_TOUT),
@@ -157,7 +157,7 @@ single_node_user_connection_channel_tracking(Config) ->
157157
[Conn3] = open_connections(Config, [0]),
158158
Chans3 = [_|_] = open_channels(Conn3, 5),
159159
?awaitMatch(1, count_connections_in(Config, Username), ?A_TOUT),
160-
[#tracked_connection{username = Username}] = connections_in(Config, Username),
160+
?awaitMatch([#tracked_connection{username = Username}], connections_in(Config, Username), ?A_TOUT),
161161
?awaitMatch(5, count_channels_in(Config, Username), ?A_TOUT),
162162
?awaitMatch(1, tracked_user_connection_count(Config, Username), ?A_TOUT),
163163
?awaitMatch(5, tracked_user_channel_count(Config, Username), ?A_TOUT),
@@ -172,7 +172,7 @@ single_node_user_connection_channel_tracking(Config) ->
172172
[?awaitMatch(true, is_process_alive(Ch), ?A_TOUT) || Ch <- Chans4],
173173
kill_connections([Conn4]),
174174
?awaitMatch(1, count_connections_in(Config, Username), ?A_TOUT),
175-
[#tracked_connection{username = Username}] = connections_in(Config, Username),
175+
?awaitMatch([#tracked_connection{username = Username}], connections_in(Config, Username), ?A_TOUT),
176176
?awaitMatch(5, count_channels_in(Config, Username), ?A_TOUT),
177177
?awaitMatch(1, tracked_user_connection_count(Config, Username), ?A_TOUT),
178178
?awaitMatch(5, tracked_user_channel_count(Config, Username), ?A_TOUT),
@@ -182,9 +182,11 @@ single_node_user_connection_channel_tracking(Config) ->
182182
[Conn5] = open_connections(Config, [0]),
183183
Chans5 = [_|_] = open_channels(Conn5, 7),
184184
?awaitMatch(2, count_connections_in(Config, Username), ?A_TOUT),
185-
[Username, Username] =
186-
lists:map(fun (#tracked_connection{username = U}) -> U end,
187-
connections_in(Config, Username)),
185+
?awaitMatch(
186+
[Username, Username],
187+
lists:map(fun (#tracked_connection{username = U}) -> U end,
188+
connections_in(Config, Username)),
189+
?A_TOUT),
188190
?awaitMatch(12, count_channels_in(Config, Username), ?A_TOUT),
189191
?awaitMatch(12, tracked_user_channel_count(Config, Username), ?A_TOUT),
190192
?awaitMatch(2, tracked_user_connection_count(Config, Username), ?A_TOUT),

deps/rabbit/test/per_user_connection_tracking_SUITE.erl

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,28 +115,42 @@ single_node_list_of_user(Config) ->
115115

116116
[Conn1] = open_connections(Config, [{0, Username1}]),
117117
?awaitMatch(1, count_connections_in(Config, Username1), ?AWAIT_TIMEOUT),
118-
[#tracked_connection{username = Username1}] = connections_in(Config, Username1),
118+
?awaitMatch(
119+
[#tracked_connection{username = Username1}],
120+
connections_in(Config, Username1),
121+
?AWAIT_TIMEOUT),
119122
close_connections([Conn1]),
120123
?awaitMatch(0, count_connections_in(Config, Username1), ?AWAIT_TIMEOUT),
121124

122125
[Conn2] = open_connections(Config, [{0, Username2}]),
123126
?awaitMatch(1, count_connections_in(Config, Username2), ?AWAIT_TIMEOUT),
124-
[#tracked_connection{username = Username2}] = connections_in(Config, Username2),
127+
?awaitMatch(
128+
[#tracked_connection{username = Username2}],
129+
connections_in(Config, Username2),
130+
?AWAIT_TIMEOUT),
125131

126132
[Conn3] = open_connections(Config, [{0, Username1}]),
127133
?awaitMatch(1, count_connections_in(Config, Username1), ?AWAIT_TIMEOUT),
128-
[#tracked_connection{username = Username1}] = connections_in(Config, Username1),
134+
?awaitMatch(
135+
[#tracked_connection{username = Username1}],
136+
connections_in(Config, Username1),
137+
?AWAIT_TIMEOUT),
129138

130139
[Conn4] = open_connections(Config, [{0, Username1}]),
131140
kill_connections([Conn4]),
132141
?awaitMatch(1, count_connections_in(Config, Username1), ?AWAIT_TIMEOUT),
133-
[#tracked_connection{username = Username1}] = connections_in(Config, Username1),
142+
?awaitMatch(
143+
[#tracked_connection{username = Username1}],
144+
connections_in(Config, Username1),
145+
?AWAIT_TIMEOUT),
134146

135147
[Conn5] = open_connections(Config, [{0, Username1}]),
136148
?awaitMatch(2, count_connections_in(Config, Username1), ?AWAIT_TIMEOUT),
137-
[Username1, Username1] =
138-
lists:map(fun (#tracked_connection{username = U}) -> U end,
139-
connections_in(Config, Username1)),
149+
?awaitMatch(
150+
[Username1, Username1],
151+
lists:map(fun (#tracked_connection{username = U}) -> U end,
152+
connections_in(Config, Username1)),
153+
?AWAIT_TIMEOUT),
140154

141155
close_connections([Conn2, Conn3, Conn5]),
142156
rabbit_ct_broker_helpers:delete_user(Config, Username2),

deps/rabbit/test/proxy_protocol_SUITE.erl

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
-include_lib("common_test/include/ct.hrl").
1111
-include_lib("rabbit_common/include/rabbit.hrl").
1212

13+
-include_lib("rabbitmq_ct_helpers/include/rabbit_assert.hrl").
14+
1315
-compile(export_all).
1416

1517
-define(TIMEOUT, 5000).
@@ -65,8 +67,10 @@ proxy_protocol_v1(Config) ->
6567
{ok, _Packet} = gen_tcp:recv(Socket, 0, ?TIMEOUT),
6668
ConnectionName = rabbit_ct_broker_helpers:rpc(Config, 0,
6769
?MODULE, connection_name, []),
70+
ct:pal("Connection name: ~s", [ConnectionName]),
6871
match = re:run(ConnectionName, <<"^192.168.1.1:80 -> 192.168.1.2:81$">>, [{capture, none}]),
6972
gen_tcp:close(Socket),
73+
wait_for_connection_close(Config),
7074
ok.
7175

7276
proxy_protocol_v1_tls(Config) ->
@@ -80,8 +84,10 @@ proxy_protocol_v1_tls(Config) ->
8084
{ok, _Packet} = ssl:recv(SslSocket, 0, ?TIMEOUT),
8185
ConnectionName = rabbit_ct_broker_helpers:rpc(Config, 0,
8286
?MODULE, connection_name, []),
87+
ct:pal("Connection name: ~s", [ConnectionName]),
8388
match = re:run(ConnectionName, <<"^192.168.1.1:80 -> 192.168.1.2:81$">>, [{capture, none}]),
8489
gen_tcp:close(Socket),
90+
wait_for_connection_close(Config),
8591
ok.
8692

8793
proxy_protocol_v2_local(Config) ->
@@ -97,13 +103,22 @@ proxy_protocol_v2_local(Config) ->
97103
{ok, _Packet} = gen_tcp:recv(Socket, 0, ?TIMEOUT),
98104
ConnectionName = rabbit_ct_broker_helpers:rpc(Config, 0,
99105
?MODULE, connection_name, []),
106+
ct:pal("Connection name: ~s", [ConnectionName]),
100107
match = re:run(ConnectionName, <<"^127.0.0.1:\\d+ -> 127.0.0.1:\\d+$">>, [{capture, none}]),
101108
gen_tcp:close(Socket),
109+
wait_for_connection_close(Config),
102110
ok.
103111

104112
connection_name() ->
105-
Pids = pg_local:get_members(rabbit_connections),
106-
Pid = lists:nth(1, Pids),
113+
?awaitMatch([_], pg_local:get_members(rabbit_connections), 30000),
114+
[Pid] = pg_local:get_members(rabbit_connections),
107115
{dictionary, Dict} = process_info(Pid, dictionary),
108116
{process_name, {rabbit_reader, ConnectionName}} = lists:keyfind(process_name, 1, Dict),
109117
ConnectionName.
118+
119+
wait_for_connection_close(Config) ->
120+
?awaitMatch(
121+
[],
122+
rabbit_ct_broker_helpers:rpc(
123+
Config, 0, pg_local, get_members, [rabbit_connnections]),
124+
30000).

0 commit comments

Comments
 (0)