Skip to content

Commit c636182

Browse files
Merge pull request #15539 from rabbitmq/test-flakes-feb23-2026
Flaky test fixes
2 parents af945e2 + bb95eb9 commit c636182

5 files changed

Lines changed: 49 additions & 15 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ jobs:
105105
sudo apt-get update && \
106106
sudo apt-get install -y \
107107
ldap-utils \
108-
slapd
108+
slapd \
109+
util-linux
109110
110111
sudo systemctl stop slapd
111112

deps/rabbit/test/classic_queue_SUITE.erl

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,14 @@ leader_locator_client_local(Config) ->
152152
?assertEqual({'queue.declare_ok', Q, 0, 0},
153153
declare(Ch, Q, [{<<"x-queue-type">>, longstr, <<"classic">>},
154154
{<<"x-queue-leader-locator">>, longstr, <<"client-local">>}])),
155-
{ok, Leader0} = rabbit_ct_broker_helpers:rpc(Config, Server, rabbit_amqqueue, lookup, [rabbit_misc:r(<<"/">>, queue, Q)]),
155+
{ok, Leader0} = ?awaitMatch(
156+
{ok, _},
157+
rabbit_ct_broker_helpers:rpc(Config,
158+
Server,
159+
rabbit_amqqueue,
160+
lookup,
161+
[rabbit_misc:r(<<"/">>, queue, Q)]),
162+
5000),
156163
Leader = amqqueue:qnode(Leader0),
157164
?assertEqual(Server, Leader),
158165
?assertMatch(#'queue.delete_ok'{},
@@ -175,12 +182,19 @@ test_leader_locator(Config, Argument, Strategies) ->
175182

176183
[begin
177184
Leaders = [begin
178-
?assertMatch({'queue.declare_ok', Q, 0, 0},
185+
?assertEqual({'queue.declare_ok', Q, 0, 0},
179186
declare(Ch, Q,
180187
[{<<"x-queue-type">>, longstr, <<"classic">>},
181188
{Argument, longstr, Strategy}])),
182189

183-
{ok, Leader0} = rabbit_ct_broker_helpers:rpc(Config, Server, rabbit_amqqueue, lookup, [rabbit_misc:r(<<"/">>, queue, Q)]),
190+
{ok, Leader0} = ?awaitMatch(
191+
{ok, _},
192+
rabbit_ct_broker_helpers:rpc(Config,
193+
Server,
194+
rabbit_amqqueue,
195+
lookup,
196+
[rabbit_misc:r(<<"/">>, queue, Q)]),
197+
5000),
184198
Leader = amqqueue:qnode(Leader0),
185199
Leader
186200
end || Q <- Qs],

deps/rabbitmq_cli/lib/rabbitmq/cli/core/distribution.ex

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,24 @@ defmodule RabbitMQ.CLI.Core.Distribution do
101101
throw(err)
102102

103103
rmq_hostname ->
104-
# This limits the number of possible unique node names used by CLI tools to avoid
105-
# the atom table from growing above the node limit. We must use reasonably unique IDs
106-
# to allow for concurrent CLI tool execution.
107-
#
108-
# Enum.random/1 is constant time and space with range arguments https://hexdocs.pm/elixir/Enum.html#random/1.
109-
id = Enum.random(1..1024)
104+
id = generate_cli_node_id()
110105
String.to_atom("rabbitmqcli-#{id}-#{rmq_hostname}")
111106
end
112107
end
108+
109+
# The main goal is to limit the number of possible unique node names used by CLI
110+
# tools to avoid the atom table from growing above the node limit.
111+
# However, when RABBITMQ_CTL_UNIQUE_NODE_NAME is set, each CLI invocation gets
112+
# a guaranteed unique node name. This avoids name collisions in CI environments
113+
# that run many CLI commands concurrently. The unbounded atom
114+
# table growth is acceptable in short-lived CI environments.
115+
defp generate_cli_node_id do
116+
case System.get_env("RABBITMQ_CTL_UNIQUE_NODE_NAME") do
117+
nil ->
118+
Enum.random(1..1024)
119+
120+
_ ->
121+
"#{:os.getpid()}"
122+
end
123+
end
113124
end

deps/rabbitmq_ct_helpers/src/rabbit_ct_broker_helpers.erl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,7 +1335,8 @@ rabbitmqctl(Config, Node, Args, Timeout) ->
13351335
{"RABBITMQ_MNESIA_DIR", ?config(data_dir, NodeConfig)},
13361336
{"RABBITMQ_PLUGINS_DIR", ?config(plugins_dir, NodeConfig)},
13371337
{"RABBITMQ_ENABLED_PLUGINS_FILE",
1338-
?config(enabled_plugins_file, NodeConfig)}
1338+
?config(enabled_plugins_file, NodeConfig)},
1339+
{"RABBITMQ_CTL_UNIQUE_NODE_NAME", "true"}
13391340
],
13401341
Ret = rabbit_ct_helpers:get_config(
13411342
NodeConfig, enabled_feature_flags_list_file),
@@ -1366,7 +1367,8 @@ rabbitmq_queues(Config, Node, Args) ->
13661367
{"RABBITMQ_MNESIA_DIR", ?config(data_dir, NodeConfig)},
13671368
{"RABBITMQ_PLUGINS_DIR", ?config(plugins_dir, NodeConfig)},
13681369
{"RABBITMQ_ENABLED_PLUGINS_FILE",
1369-
?config(enabled_plugins_file, NodeConfig)}
1370+
?config(enabled_plugins_file, NodeConfig)},
1371+
{"RABBITMQ_CTL_UNIQUE_NODE_NAME", "true"}
13701372
],
13711373
Ret = rabbit_ct_helpers:get_config(
13721374
NodeConfig, enabled_feature_flags_list_file),
@@ -1390,7 +1392,8 @@ rabbitmq_streams(Config, Node, Args) ->
13901392
{"RABBITMQ_MNESIA_DIR", ?config(data_dir, NodeConfig)},
13911393
{"RABBITMQ_PLUGINS_DIR", ?config(plugins_dir, NodeConfig)},
13921394
{"RABBITMQ_ENABLED_PLUGINS_FILE",
1393-
?config(enabled_plugins_file, NodeConfig)}
1395+
?config(enabled_plugins_file, NodeConfig)},
1396+
{"RABBITMQ_CTL_UNIQUE_NODE_NAME", "true"}
13941397
],
13951398
Ret = rabbit_ct_helpers:get_config(
13961399
NodeConfig, enabled_feature_flags_list_file),
@@ -1414,7 +1417,8 @@ rabbitmq_diagnostics(Config, Node, Args) ->
14141417
{"RABBITMQ_MNESIA_DIR", ?config(data_dir, NodeConfig)},
14151418
{"RABBITMQ_PLUGINS_DIR", ?config(plugins_dir, NodeConfig)},
14161419
{"RABBITMQ_ENABLED_PLUGINS_FILE",
1417-
?config(enabled_plugins_file, NodeConfig)}
1420+
?config(enabled_plugins_file, NodeConfig)},
1421+
{"RABBITMQ_CTL_UNIQUE_NODE_NAME", "true"}
14181422
],
14191423
Cmd = [Rabbitmqdiagnostics, "-n", Nodename | Args],
14201424
rabbit_ct_helpers:exec(Cmd, [{env, Env}]).
@@ -2252,7 +2256,8 @@ plugin_action(Config, Node, Args) ->
22522256
{"RABBITMQ_MNESIA_DIR", ?config(data_dir, NodeConfig)},
22532257
{"RABBITMQ_PLUGINS_DIR", ?config(plugins_dir, NodeConfig)},
22542258
{"RABBITMQ_ENABLED_PLUGINS_FILE",
2255-
?config(enabled_plugins_file, NodeConfig)}
2259+
?config(enabled_plugins_file, NodeConfig)},
2260+
{"RABBITMQ_CTL_UNIQUE_NODE_NAME", "true"}
22562261
],
22572262
Cmd = [Rabbitmqplugins, "-n", Nodename | Args],
22582263
{ok, _} = rabbit_ct_helpers:exec(Cmd, [{env, Env}]),

deps/rabbitmq_mqtt/test/auth_SUITE.erl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,10 @@ will_queue_publish_permission_topic_write(Config) ->
898898
will_queue_delete_permission(Config) ->
899899
set_permissions(".*", ".*", ".*", Config),
900900
ClientId = atom_to_binary(?FUNCTION_NAME),
901+
Vhost = ?config(mqtt_vhost, Config),
901902
disconnect_with_delayed_will(ClientId, Config),
903+
QName = rabbit_misc:r(Vhost, queue, <<"mqtt-will-", ClientId/binary>>),
904+
?awaitMatch({ok, _}, rpc(Config, 0, rabbit_amqqueue, lookup, [QName]), 5000),
902905
set_permissions(<<>>, ".*", ".*", Config),
903906
%% Now we have a Will queue that user doesn't have permission to delete.
904907
%% Resuming the session should fail.

0 commit comments

Comments
 (0)