1010
1111-include_lib (" common_test/include/ct.hrl" ).
1212-include_lib (" eunit/include/eunit.hrl" ).
13+ -include_lib (" rabbitmq_ct_helpers/include/rabbit_assert.hrl" ).
1314
1415-define (TIMEOUT , 5000 ).
1516
@@ -70,9 +71,8 @@ proxy_protocol_v1(Config) ->
7071 ok = inet :send (Socket , " PROXY TCP4 192.168.1.1 192.168.1.2 80 81\r\n " ),
7172 ok = inet :send (Socket , stomp_connect_frame ()),
7273 {ok , _Packet } = gen_tcp :recv (Socket , 0 , ? TIMEOUT ),
73- ConnectionName = rabbit_ct_broker_helpers :rpc (Config , 0 ,
74- ? MODULE , connection_name , []),
75- match = re :run (ConnectionName , <<" ^192.168.1.1:80 -> 192.168.1.2:81$" >>, [{capture , none }]),
74+ await_connection_name_match (
75+ Config , <<" ^192.168.1.1:80 -> 192.168.1.2:81$" >>),
7676 gen_tcp :close (Socket ),
7777 ok .
7878
@@ -85,9 +85,8 @@ proxy_protocol_v1_tls(Config) ->
8585 {ok , SslSocket } = ssl :connect (Socket , [{verify , verify_none }], ? TIMEOUT ),
8686 ok = ssl :send (SslSocket , stomp_connect_frame ()),
8787 {ok , _Packet } = ssl :recv (SslSocket , 0 , ? TIMEOUT ),
88- ConnectionName = rabbit_ct_broker_helpers :rpc (Config , 0 ,
89- ? MODULE , connection_name , []),
90- match = re :run (ConnectionName , <<" ^192.168.1.1:80 -> 192.168.1.2:81$" >>, [{capture , none }]),
88+ await_connection_name_match (
89+ Config , <<" ^192.168.1.1:80 -> 192.168.1.2:81$" >>),
9190 gen_tcp :close (Socket ),
9291 ok .
9392
@@ -102,17 +101,31 @@ proxy_protocol_v2_local(Config) ->
102101 ok = inet :send (Socket , ranch_proxy_header :header (ProxyInfo )),
103102 ok = inet :send (Socket , stomp_connect_frame ()),
104103 {ok , _Packet } = gen_tcp :recv (Socket , 0 , ? TIMEOUT ),
105- ConnectionName = rabbit_ct_broker_helpers :rpc (Config , 0 ,
106- ? MODULE , connection_name , []),
107- match = re :run (ConnectionName , <<" ^127.0.0.1:\\ d+ -> 127.0.0.1:\\ d+$" >>, [{capture , none }]),
104+ await_connection_name_match (
105+ Config , <<" ^127.0.0.1:\\ d+ -> 127.0.0.1:\\ d+$" >>),
108106 gen_tcp :close (Socket ),
109107 ok .
110108
111- connection_name () ->
109+ % % The `connection_created' ETS table is populated asynchronously by
110+ % % the management agent; wait for an entry whose `name' matches the
111+ % % pattern.
112+ await_connection_name_match (Config , Pattern ) ->
113+ ? awaitMatch (true ,
114+ rabbit_ct_broker_helpers :rpc (
115+ Config , 0 , ? MODULE , has_connection_name_matching , [Pattern ]),
116+ 30_000 ).
117+
118+ has_connection_name_matching (Pattern ) ->
112119 Connections = ets :tab2list (connection_created ),
113- {_Key , Values } = lists :nth (1 , Connections ),
114- {_ , Name } = lists :keyfind (name , 1 , Values ),
115- Name .
120+ lists :any (
121+ fun ({_Key , Values }) ->
122+ case lists :keyfind (name , 1 , Values ) of
123+ {_ , Name } ->
124+ re :run (Name , Pattern , [{capture , none }]) =:= match ;
125+ false ->
126+ false
127+ end
128+ end , Connections ).
116129
117130merge_app_env (StompConfig , Config ) ->
118131 rabbit_ct_helpers :merge_app_env (Config , StompConfig ).
0 commit comments