Skip to content

Commit 94b4a6a

Browse files
authored
Merge pull request #14206 from rabbitmq/fix-test-flakes-2025Q2
Collection of test fixes
2 parents 4ac82b6 + 0fb74ba commit 94b4a6a

16 files changed

+182
-150
lines changed

deps/rabbit/test/amqp_client_SUITE.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4087,7 +4087,7 @@ list_connections(Config) ->
40874087

40884088
%% CLI should list AMQP 1.0 container-id
40894089
{ok, StdOut1} = rabbit_ct_broker_helpers:rabbitmqctl(Config, 0, ["list_connections", "--silent", "container_id"]),
4090-
ContainerIds0 = re:split(StdOut1, <<"\n">>, [trim]),
4090+
ContainerIds0 = re:split(string:trim(StdOut1), <<"\n">>, [trim]),
40914091
ContainerIds = lists:sort(ContainerIds0),
40924092
?assertEqual([<<>>, ContainerId0, ContainerId2],
40934093
ContainerIds),
@@ -4749,7 +4749,7 @@ idle_time_out_on_server(Config) ->
47494749
ct:fail({missing_event, ?LINE})
47504750
end
47514751
after
4752-
?assert(rpc(Config, meck, validate, [Mod])),
4752+
_ = rpc(Config, meck, validate, [Mod]),
47534753
ok = rpc(Config, meck, unload, [Mod]),
47544754
ok = rpc(Config, application, set_env, [App, Par, DefaultVal])
47554755
end.

deps/rabbit/test/backing_queue_SUITE.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,18 +1445,18 @@ variable_queue_restart_large_seq_id2(VQ0, QName) ->
14451445
Terms = variable_queue_read_terms(QName),
14461446
Count = proplists:get_value(next_seq_id, Terms),
14471447

1448-
%% set a very high next_seq_id as if 100M messages have been
1448+
%% set a very high next_seq_id as if 100 billion messages have been
14491449
%% published and consumed
1450-
Terms2 = lists:keyreplace(next_seq_id, 1, Terms, {next_seq_id, 100_000_000}),
1450+
Terms2 = lists:keyreplace(next_seq_id, 1, Terms, {next_seq_id, 100_000_000_000}),
14511451

14521452
{TInit, VQ3} =
14531453
timer:tc(
14541454
fun() -> variable_queue_init(test_amqqueue(QName, true), Terms2) end,
14551455
millisecond),
14561456
%% even with a very high next_seq_id start of an empty queue
1457-
%% should be quick (few milliseconds, but let's give it 100ms, to
1457+
%% should be quick (few milliseconds, but let's give it 500ms, to
14581458
%% avoid flaking on slow servers)
1459-
{true, _} = {TInit < 100, TInit},
1459+
{true, _} = {TInit < 500, TInit},
14601460

14611461
%% should be empty now
14621462
true = rabbit_variable_queue:is_empty(VQ3),

deps/rabbit/test/cluster_minority_SUITE.erl

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -387,28 +387,26 @@ remove_node_when_seed_node_is_leader(Config) ->
387387
AMember = {rabbit_khepri:get_store_id(), A},
388388
ra:transfer_leadership(AMember, AMember),
389389
clustering_utils:assert_cluster_status({Cluster, Cluster}, Cluster),
390+
ct:pal("Waiting for cluster change permitted on node A"),
391+
?awaitMatch(
392+
{ok, #{cluster_change_permitted := true,
393+
leader_id := AMember}, AMember},
394+
rabbit_ct_broker_helpers:rpc(
395+
Config1, A, ra, member_overview, [AMember]),
396+
60000),
397+
{ok, Overview, AMember} = rabbit_ct_broker_helpers:rpc(
398+
Config1, A, ra, member_overview, [AMember]),
399+
ct:pal("Member A overview: ~p", [maps:remove(machine, Overview)]),
390400

391401
%% Minority partition: A
392402
partition_3_node_cluster(Config1),
393403

394-
Pong = ra:ping(AMember, 10000),
395-
ct:pal("Member A state: ~0p", [Pong]),
396-
case Pong of
397-
{pong, leader} ->
398-
?awaitMatch(
399-
{ok, #{cluster_change_permitted := true}, _},
400-
rabbit_ct_broker_helpers:rpc(
401-
Config1, A, ra, member_overview, [AMember]),
402-
60000),
403-
?awaitMatch(
404-
ok,
405-
rabbit_control_helper:command(
406-
forget_cluster_node, A, [atom_to_list(B)], []),
407-
60000);
408-
Ret ->
409-
ct:pal("A is not the expected leader: ~p", [Ret]),
410-
{skip, "Node A was not a leader"}
411-
end.
404+
?assertEqual({pong, leader}, ra:ping(AMember, 10000)),
405+
?awaitMatch(
406+
ok,
407+
rabbit_control_helper:command(
408+
forget_cluster_node, A, [atom_to_list(B)], []),
409+
60000).
412410

413411
remove_node_when_seed_node_is_follower(Config) ->
414412
[A, B, C | _] = rabbit_ct_broker_helpers:get_node_configs(
@@ -418,36 +416,31 @@ remove_node_when_seed_node_is_follower(Config) ->
418416
Cluster = [A, B, C],
419417
Config1 = rabbit_ct_broker_helpers:cluster_nodes(Config, Cluster),
420418

419+
AMember = {rabbit_khepri:get_store_id(), A},
421420
CMember = {rabbit_khepri:get_store_id(), C},
422421
ra:transfer_leadership(CMember, CMember),
423422
clustering_utils:assert_cluster_status({Cluster, Cluster}, Cluster),
423+
?awaitMatch(
424+
{ok, #{cluster_change_permitted := true,
425+
leader_id := CMember}, AMember},
426+
rabbit_ct_broker_helpers:rpc(
427+
Config1, A, ra, member_overview, [AMember]),
428+
60000),
429+
{ok, Overview, AMember} = rabbit_ct_broker_helpers:rpc(
430+
Config1, A, ra, member_overview, [AMember]),
431+
ct:pal("Member A overview: ~p", [maps:remove(machine, Overview)]),
424432

425433
%% Minority partition: A
426434
partition_3_node_cluster(Config1),
427435

428-
AMember = {rabbit_khepri:get_store_id(), A},
429-
Pong = ra:ping(AMember, 10000),
430-
ct:pal("Member A state: ~0p", [Pong]),
431-
case Pong of
432-
{pong, State}
433-
when State =:= follower orelse State =:= pre_vote ->
434-
Ret = rabbit_control_helper:command(
435-
forget_cluster_node, A, [atom_to_list(B)], []),
436-
?assertMatch({error, _, _}, Ret),
437-
{error, _, Msg} = Ret,
438-
?assertEqual(
439-
match,
440-
re:run(
441-
Msg, "Khepri cluster could be in minority",
442-
[{capture, none}]));
443-
{pong, await_condition} ->
444-
Ret = rabbit_control_helper:command(
445-
forget_cluster_node, A, [atom_to_list(B)], []),
446-
?assertMatch(ok, Ret);
447-
Ret ->
448-
ct:pal("A is not the expected leader: ~p", [Ret]),
449-
{skip, "Node A was not a leader"}
450-
end.
436+
Ret = rabbit_control_helper:command(
437+
forget_cluster_node, A, [atom_to_list(B)], []),
438+
?assertMatch({error, _, _}, Ret),
439+
{error, _, Msg} = Ret,
440+
?assertEqual(
441+
match,
442+
re:run(
443+
Msg, "Khepri cluster could be in minority", [{capture, none}])).
451444

452445
enable_feature_flag(Config) ->
453446
[A | _] = rabbit_ct_broker_helpers:get_node_configs(Config, nodename),

deps/rabbit/test/feature_flags_SUITE.erl

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
%% License, v. 2.0. If a copy of the MPL was not distributed with this
33
%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
44
%%
5-
%% Copyright (c) 2007-2025 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
5+
%% Copyright (c) 2019-2025 Broadcom. All Rights Reserved. The term “Broadcom”
6+
%% refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
67
%%
78

89
-module(feature_flags_SUITE).
@@ -197,14 +198,15 @@ init_per_group(clustering, Config) ->
197198
{rmq_nodes_clustered, false},
198199
{start_rmq_with_plugins_disabled, true}]),
199200
Config2 = rabbit_ct_helpers:merge_app_env(
200-
Config1, {rabbit, [{forced_feature_flags_on_init, [
201-
restart_streams,
202-
stream_sac_coordinator_unblock_group,
203-
stream_update_config_command,
204-
stream_filtering,
205-
message_containers,
206-
quorum_queue_non_voters
207-
]}]}),
201+
Config1, {rabbit, [{forced_feature_flags_on_init,
202+
[
203+
restart_streams,
204+
stream_sac_coordinator_unblock_group,
205+
stream_update_config_command,
206+
stream_filtering,
207+
message_containers,
208+
quorum_queue_non_voters
209+
]}]}),
208210
rabbit_ct_helpers:run_setup_steps(Config2, [fun prepare_my_plugin/1]);
209211
init_per_group(activating_plugin, Config) ->
210212
Config1 = rabbit_ct_helpers:set_config(
@@ -219,7 +221,8 @@ init_per_group(_, Config) ->
219221
end_per_group(_, Config) ->
220222
Config.
221223

222-
init_per_testcase(enable_feature_flag_when_ff_file_is_unwritable = Testcase, Config) ->
224+
init_per_testcase(
225+
enable_feature_flag_when_ff_file_is_unwritable = Testcase, Config) ->
223226
case erlang:system_info(otp_release) of
224227
"26" ->
225228
{skip, "Hits a crash in Mnesia fairly frequently"};
@@ -1284,11 +1287,13 @@ activating_plugin_with_new_ff_enabled(Config) ->
12841287
ok.
12851288

12861289
enable_plugin_feature_flag_after_deactivating_plugin(Config) ->
1287-
case rabbit_ct_broker_helpers:is_feature_flag_enabled(Config, 'rabbitmq_4.0.0') of
1290+
RabbitMQ40Enabled = rabbit_ct_broker_helpers:is_feature_flag_enabled(
1291+
Config, 'rabbitmq_4.0.0'),
1292+
case RabbitMQ40Enabled of
12881293
true ->
12891294
ok;
12901295
false ->
1291-
throw({skip, "this test triggers a bug present in 3.13"})
1296+
throw({skip, "This test triggers a bug present in 3.13"})
12921297
end,
12931298

12941299
FFSubsysOk = is_feature_flag_subsystem_available(Config),
@@ -1321,11 +1326,13 @@ enable_plugin_feature_flag_after_deactivating_plugin(Config) ->
13211326
ok.
13221327

13231328
restart_node_with_unknown_enabled_feature_flag(Config) ->
1324-
case rabbit_ct_broker_helpers:is_feature_flag_enabled(Config, 'rabbitmq_4.0.0') of
1329+
RabbitMQ40Enabled = rabbit_ct_broker_helpers:is_feature_flag_enabled(
1330+
Config, 'rabbitmq_4.0.0'),
1331+
case RabbitMQ40Enabled of
13251332
true ->
13261333
ok;
13271334
false ->
1328-
throw({skip, "this test triggers a bug present in 3.13"})
1335+
throw({skip, "This test triggers a bug present in 3.13"})
13291336
end,
13301337

13311338
FFSubsysOk = is_feature_flag_subsystem_available(Config),

deps/rabbit/test/metrics_SUITE.erl

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,9 @@ add_rem_counter(Config, {Initial, Ops}, {AddFun, RemFun}, Tables) ->
301301

302302
connection(Config) ->
303303
Conn = rabbit_ct_client_helpers:open_unmanaged_connection(Config),
304-
[_] = read_table_rpc(Config, connection_created),
305-
[_] = read_table_rpc(Config, connection_metrics),
306-
[_] = read_table_rpc(Config, connection_coarse_metrics),
304+
?awaitMatch([_], read_table_rpc(Config, connection_created), 30000),
305+
?awaitMatch([_], read_table_rpc(Config, connection_metrics), 30000),
306+
?awaitMatch([_], read_table_rpc(Config, connection_coarse_metrics), 30000),
307307
ok = rabbit_ct_client_helpers:close_connection(Conn),
308308
force_metric_gc(Config),
309309
?awaitMatch([], read_table_rpc(Config, connection_created),
@@ -317,25 +317,25 @@ connection(Config) ->
317317
channel(Config) ->
318318
Conn = rabbit_ct_client_helpers:open_unmanaged_connection(Config),
319319
{ok, Chan} = amqp_connection:open_channel(Conn),
320-
[_] = read_table_rpc(Config, channel_created),
321-
[_] = read_table_rpc(Config, channel_metrics),
322-
[_] = read_table_rpc(Config, channel_process_metrics),
320+
?awaitMatch([_], read_table_rpc(Config, channel_created), 30000),
321+
?awaitMatch([_], read_table_rpc(Config, channel_metrics), 30000),
322+
?awaitMatch([_], read_table_rpc(Config, channel_process_metrics), 30000),
323323
ok = amqp_channel:close(Chan),
324-
[] = read_table_rpc(Config, channel_created),
325-
[] = read_table_rpc(Config, channel_metrics),
326-
[] = read_table_rpc(Config, channel_process_metrics),
324+
?awaitMatch([], read_table_rpc(Config, channel_created), 30000),
325+
?awaitMatch([], read_table_rpc(Config, channel_metrics), 30000),
326+
?awaitMatch([], read_table_rpc(Config, channel_process_metrics), 30000),
327327
ok = rabbit_ct_client_helpers:close_connection(Conn).
328328

329329
channel_connection_close(Config) ->
330330
Conn = rabbit_ct_client_helpers:open_unmanaged_connection(Config),
331331
{ok, _} = amqp_connection:open_channel(Conn),
332-
[_] = read_table_rpc(Config, channel_created),
333-
[_] = read_table_rpc(Config, channel_metrics),
334-
[_] = read_table_rpc(Config, channel_process_metrics),
332+
?awaitMatch([_], read_table_rpc(Config, channel_created), 30000),
333+
?awaitMatch([_], read_table_rpc(Config, channel_metrics), 30000),
334+
?awaitMatch([_], read_table_rpc(Config, channel_process_metrics), 30000),
335335
ok = rabbit_ct_client_helpers:close_connection(Conn),
336-
[] = read_table_rpc(Config, channel_created),
337-
[] = read_table_rpc(Config, channel_metrics),
338-
[] = read_table_rpc(Config, channel_process_metrics).
336+
?awaitMatch([], read_table_rpc(Config, channel_created), 30000),
337+
?awaitMatch([], read_table_rpc(Config, channel_metrics), 30000),
338+
?awaitMatch([], read_table_rpc(Config, channel_process_metrics), 30000).
339339

340340
channel_queue_delete_queue(Config) ->
341341
Conn = rabbit_ct_client_helpers:open_unmanaged_connection(Config),
@@ -344,14 +344,14 @@ channel_queue_delete_queue(Config) ->
344344
ensure_exchange_metrics_populated(Chan, Queue),
345345
ensure_channel_queue_metrics_populated(Chan, Queue),
346346
force_channel_stats(Config),
347-
[_] = read_table_rpc(Config, channel_queue_metrics),
348-
[_] = read_table_rpc(Config, channel_queue_exchange_metrics),
347+
?awaitMatch([_], read_table_rpc(Config, channel_queue_metrics), 30000),
348+
?awaitMatch([_], read_table_rpc(Config, channel_queue_exchange_metrics), 30000),
349349

350350
delete_queue(Chan, Queue),
351351
force_metric_gc(Config),
352352
% ensure removal of queue cleans up channel_queue metrics
353-
[] = read_table_rpc(Config, channel_queue_exchange_metrics),
354-
[] = read_table_rpc(Config, channel_queue_metrics),
353+
?awaitMatch([], read_table_rpc(Config, channel_queue_exchange_metrics), 30000),
354+
?awaitMatch([], read_table_rpc(Config, channel_queue_metrics), 30000),
355355
ok = rabbit_ct_client_helpers:close_connection(Conn),
356356
ok.
357357

@@ -362,26 +362,26 @@ channel_queue_exchange_consumer_close_connection(Config) ->
362362
ensure_exchange_metrics_populated(Chan, Queue),
363363
force_channel_stats(Config),
364364

365-
[_] = read_table_rpc(Config, channel_exchange_metrics),
366-
[_] = read_table_rpc(Config, channel_queue_exchange_metrics),
365+
?awaitMatch([_], read_table_rpc(Config, channel_exchange_metrics), 30000),
366+
?awaitMatch([_], read_table_rpc(Config, channel_queue_exchange_metrics), 30000),
367367

368368
ensure_channel_queue_metrics_populated(Chan, Queue),
369369
force_channel_stats(Config),
370-
[_] = read_table_rpc(Config, channel_queue_metrics),
370+
?awaitMatch([_], read_table_rpc(Config, channel_queue_metrics), 30000),
371371

372372
Sub = #'basic.consume'{queue = Queue},
373373
#'basic.consume_ok'{consumer_tag = _} =
374374
amqp_channel:call(Chan, Sub),
375375

376-
[_] = read_table_rpc(Config, consumer_created),
376+
?awaitMatch([_], read_table_rpc(Config, consumer_created), 30000),
377377

378378
ok = rabbit_ct_client_helpers:close_connection(Conn),
379379
% ensure cleanup happened
380380
force_metric_gc(Config),
381-
[] = read_table_rpc(Config, channel_exchange_metrics),
382-
[] = read_table_rpc(Config, channel_queue_exchange_metrics),
383-
[] = read_table_rpc(Config, channel_queue_metrics),
384-
[] = read_table_rpc(Config, consumer_created),
381+
?awaitMatch([], read_table_rpc(Config, channel_exchange_metrics), 30000),
382+
?awaitMatch([], read_table_rpc(Config, channel_queue_exchange_metrics), 30000),
383+
?awaitMatch([], read_table_rpc(Config, channel_queue_metrics), 30000),
384+
?awaitMatch([], read_table_rpc(Config, consumer_created), 30000),
385385
ok.
386386

387387

deps/rabbit/test/per_node_limit_SUITE.erl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
-include_lib("common_test/include/ct.hrl").
1111
-include_lib("amqp_client/include/amqp_client.hrl").
1212
-include_lib("eunit/include/eunit.hrl").
13+
-include_lib("rabbitmq_ct_helpers/include/rabbit_assert.hrl").
1314

1415
-compile(export_all).
1516

@@ -120,27 +121,28 @@ node_channel_limit(Config) ->
120121
ok = rabbit_ct_broker_helpers:set_full_permissions(Config, User, VHost),
121122
Conn1 = rabbit_ct_client_helpers:open_unmanaged_connection(Config, 0, VHost),
122123
Conn2 = rabbit_ct_client_helpers:open_unmanaged_connection(Config, 0, VHost),
123-
0 = count_channels_per_node(Config),
124+
?awaitMatch(0, count_channels_per_node(Config), 30000),
124125

125126
lists:foreach(fun(N) when (N band 1) == 1 -> {ok, _} = open_channel(Conn1);
126127
(_) -> {ok,_ } = open_channel(Conn2)
127128
end, lists:seq(1, 5)),
128129

129-
5 = count_channels_per_node(Config),
130+
?awaitMatch(5, count_channels_per_node(Config), 30000),
130131
%% In total 5 channels are open on this node, so a new one, regardless of
131132
%% connection, will not be allowed. It will terminate the connection with
132133
%% its channels too. So
133134
{error, not_allowed_crash} = open_channel(Conn2),
134-
3 = count_channels_per_node(Config),
135+
?awaitMatch(3, count_channels_per_node(Config), 30000),
135136
%% As the connection is dead, so are the 2 channels, so we should be able to
136137
%% create 2 more on Conn1
137138
{ok , _} = open_channel(Conn1),
138139
{ok , _} = open_channel(Conn1),
140+
?awaitMatch(5, count_channels_per_node(Config), 30000),
139141
%% But not a third
140142
{error, not_allowed_crash} = open_channel(Conn1),
141143

142144
%% Now all connections are closed, so there should be 0 open connections
143-
0 = count_channels_per_node(Config),
145+
?awaitMatch(0, count_channels_per_node(Config), 30000),
144146
close_all_connections([Conn1, Conn2]),
145147

146148
rabbit_ct_broker_helpers:delete_vhost(Config, VHost),

deps/rabbit/test/per_user_connection_channel_limit_SUITE.erl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,13 @@ single_node_list_in_user(Config) ->
374374
[Conn4] = open_connections(Config, [{0, Username1}]),
375375
[_Chan4] = open_channels(Conn4, 1),
376376
close_connections([Conn4]),
377-
[#tracked_connection{username = Username1}] = connections_in(Config, Username1),
377+
rabbit_ct_helpers:await_condition(
378+
fun () ->
379+
case connections_in(Config, Username1) of
380+
[#tracked_connection{username = Username1}] -> true;
381+
_ -> false
382+
end
383+
end),
378384
[#tracked_channel{username = Username1}] = channels_in(Config, Username1),
379385

380386
[Conn5, Conn6] = open_connections(Config, [{0, Username2}, {0, Username2}]),

0 commit comments

Comments
 (0)