rabbit_stomp_test: Fix how connections are accounted
We need to count IPv4 and IPv6 separately and explicitely. Counting IPv4 connections may fail on platforms where the IPv6 listener implicitely handles IPv4. Counting IPv6 connections may fail if the host is not configured for IPv6.
This commit is contained in:
parent
1c3bbc1820
commit
0ea852b36f
|
@ -30,7 +30,24 @@ all_tests() ->
|
|||
-define(GARBAGE, <<"bdaf63dda9d78b075c748b740e7c3510ad203b07\nbdaf63dd">>).
|
||||
|
||||
count_connections() ->
|
||||
ranch_server:count_connections({acceptor, {0,0,0,0,0,0,0,0}, 61613}).
|
||||
IPv4Count = try
|
||||
%% Count IPv4 connections. On some platforms, the IPv6 listener
|
||||
%% implicitely listens to IPv4 connections too so the IPv4
|
||||
%% listener doesn't exist. Thus this try/catch. This is the case
|
||||
%% with Linux where net.ipv6.bindv6only is disabled (default in
|
||||
%% most cases).
|
||||
ranch_server:count_connections({acceptor, {0,0,0,0}, 61613})
|
||||
catch
|
||||
_:badarg -> 0
|
||||
end,
|
||||
IPv6Count = try
|
||||
%% Count IPv6 connections. We also use a try/catch block in case
|
||||
%% the host is not configured for IPv6.
|
||||
ranch_server:count_connections({acceptor, {0,0,0,0,0,0,0,0}, 61613})
|
||||
catch
|
||||
_:badarg -> 0
|
||||
end,
|
||||
IPv4Count + IPv6Count.
|
||||
|
||||
test_direct_client_connections_are_not_leaked() ->
|
||||
N = count_connections(),
|
||||
|
|
Loading…
Reference in New Issue