Skip to content

Commit 42cddb3

Browse files
committed
proxy_protocol_SUITE: Wait for connection close
[Why] `gen_tcp:close/1` simply closes the connection and doesn't wait for the broker to handle it. This sometimes causes the next test to fail because, in addition to that test's new connection, there is still the previous one's process still around waiting for the broker to notice the close. [How] We now wait for the connection to be closed at the end of a test case, and wait for the connection list to have a single element when we want to query the connnection name.
1 parent ac7bbf1 commit 42cddb3

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

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)