From 1f6d6341a061b884f169e868fd97d9ab65f545f1 Mon Sep 17 00:00:00 2001 From: Michael Klishin Date: Thu, 9 Apr 2026 17:17:49 -0700 Subject: [PATCH] Test flake chase: fix Web STOMP and Web MQTT `proxy_protocol_SUITE` flakes --- .../test/web_mqtt_proxy_protocol_SUITE.erl | 34 +++++++++++++------ .../test/proxy_protocol_SUITE.erl | 34 +++++++++++++------ 2 files changed, 48 insertions(+), 20 deletions(-) diff --git a/deps/rabbitmq_web_mqtt/test/web_mqtt_proxy_protocol_SUITE.erl b/deps/rabbitmq_web_mqtt/test/web_mqtt_proxy_protocol_SUITE.erl index a0144e9fcef1..dd0a9ccac804 100644 --- a/deps/rabbitmq_web_mqtt/test/web_mqtt_proxy_protocol_SUITE.erl +++ b/deps/rabbitmq_web_mqtt/test/web_mqtt_proxy_protocol_SUITE.erl @@ -12,6 +12,7 @@ -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). +-include_lib("rabbitmq_ct_helpers/include/rabbit_assert.hrl"). suite() -> [ @@ -87,9 +88,8 @@ proxy_protocol_v1(Config) -> {ok, _} = rfc6455_client:open(WS), rfc6455_client:send_binary(WS, rabbit_ws_test_util:mqtt_3_1_1_connect_packet()), {binary, _P} = rfc6455_client:recv(WS), - ConnectionName = rabbit_ct_broker_helpers:rpc(Config, 0, - ?MODULE, connection_name, []), - match = re:run(ConnectionName, <<"^192.168.1.1:80 -> 192.168.1.2:81$">>, [{capture, none}]), + await_connection_name_match( + Config, <<"^192.168.1.1:80 -> 192.168.1.2:81$">>), {close, _} = rfc6455_client:close(WS), ok. @@ -107,14 +107,28 @@ proxy_protocol_v2_local(Config) -> {ok, _} = rfc6455_client:open(WS), rfc6455_client:send_binary(WS, rabbit_ws_test_util:mqtt_3_1_1_connect_packet()), {binary, _P} = rfc6455_client:recv(WS), - ConnectionName = rabbit_ct_broker_helpers:rpc(Config, 0, - ?MODULE, connection_name, []), - match = re:run(ConnectionName, <<"^127.0.0.1:\\d+ -> 127.0.0.1:\\d+$">>, [{capture, none}]), + await_connection_name_match( + Config, <<"^127.0.0.1:\\d+ -> 127.0.0.1:\\d+$">>), {close, _} = rfc6455_client:close(WS), ok. -connection_name() -> +%% The `connection_created' ETS table is populated asynchronously by +%% the management agent; wait for an entry whose `name' matches the +%% pattern. +await_connection_name_match(Config, Pattern) -> + ?awaitMatch(true, + rabbit_ct_broker_helpers:rpc( + Config, 0, ?MODULE, has_connection_name_matching, [Pattern]), + 30_000). + +has_connection_name_matching(Pattern) -> Connections = ets:tab2list(connection_created), - {_Key, Values} = lists:nth(1, Connections), - {_, Name} = lists:keyfind(name, 1, Values), - Name. + lists:any( + fun({_Key, Values}) -> + case lists:keyfind(name, 1, Values) of + {_, Name} -> + re:run(Name, Pattern, [{capture, none}]) =:= match; + false -> + false + end + end, Connections). diff --git a/deps/rabbitmq_web_stomp/test/proxy_protocol_SUITE.erl b/deps/rabbitmq_web_stomp/test/proxy_protocol_SUITE.erl index 2723940419c1..526bd77dee51 100644 --- a/deps/rabbitmq_web_stomp/test/proxy_protocol_SUITE.erl +++ b/deps/rabbitmq_web_stomp/test/proxy_protocol_SUITE.erl @@ -13,6 +13,7 @@ -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). +-include_lib("rabbitmq_ct_helpers/include/rabbit_assert.hrl"). suite() -> [ @@ -93,9 +94,8 @@ proxy_protocol_v1(Config) -> Frame = stomp:marshal("CONNECT", [{"login","proxy_test"}, {"passcode", "proxy_test"}], <<>>), rfc6455_client:send(WS, Frame), {ok, _P} = rfc6455_client:recv(WS), - ConnectionName = rabbit_ct_broker_helpers:rpc(Config, 0, - ?MODULE, connection_name, []), - match = re:run(ConnectionName, <<"^192.168.1.1:80 -> 192.168.1.2:81$">>, [{capture, none}]), + await_connection_name_match( + Config, <<"^192.168.1.1:80 -> 192.168.1.2:81$">>), {close, _} = rfc6455_client:close(WS), ok. @@ -115,14 +115,28 @@ proxy_protocol_v2_local(Config) -> Frame = stomp:marshal("CONNECT", [{"login","proxy_test"}, {"passcode", "proxy_test"}], <<>>), rfc6455_client:send(WS, Frame), {ok, _P} = rfc6455_client:recv(WS), - ConnectionName = rabbit_ct_broker_helpers:rpc(Config, 0, - ?MODULE, connection_name, []), - match = re:run(ConnectionName, <<"^127.0.0.1:\\d+ -> 127.0.0.1:\\d+$">>, [{capture, none}]), + await_connection_name_match( + Config, <<"^127.0.0.1:\\d+ -> 127.0.0.1:\\d+$">>), {close, _} = rfc6455_client:close(WS), ok. -connection_name() -> +%% The `connection_created' ETS table is populated asynchronously by +%% the management agent; wait for an entry whose `name' matches the +%% pattern. +await_connection_name_match(Config, Pattern) -> + ?awaitMatch(true, + rabbit_ct_broker_helpers:rpc( + Config, 0, ?MODULE, has_connection_name_matching, [Pattern]), + 30_000). + +has_connection_name_matching(Pattern) -> Connections = ets:tab2list(connection_created), - {_Key, Values} = lists:nth(1, Connections), - {_, Name} = lists:keyfind(name, 1, Values), - Name. + lists:any( + fun({_Key, Values}) -> + case lists:keyfind(name, 1, Values) of + {_, Name} -> + re:run(Name, Pattern, [{capture, none}]) =:= match; + false -> + false + end + end, Connections).