Browse Source

Add a test for double removal of connections

Loïc Hoguin 8 years ago
parent
commit
c3eb7832e2
2 changed files with 22 additions and 9 deletions
  1. 17 4
      test/acceptor_SUITE.erl
  2. 5 5
      test/remove_conn_and_wait_protocol.erl

+ 17 - 4
test/acceptor_SUITE.erl

@@ -32,6 +32,7 @@ groups() ->
 		tcp_max_connections,
 		tcp_max_connections,
 		tcp_max_connections_and_beyond,
 		tcp_max_connections_and_beyond,
 		tcp_max_connections_infinity,
 		tcp_max_connections_infinity,
+		tcp_remove_connections,
 		tcp_set_max_connections,
 		tcp_set_max_connections,
 		tcp_set_max_connections_clean,
 		tcp_set_max_connections_clean,
 		tcp_upgrade,
 		tcp_upgrade,
@@ -68,7 +69,7 @@ misc_bad_transport(_) ->
 	ok.
 	ok.
 
 
 misc_bad_transport_options(_) ->
 misc_bad_transport_options(_) ->
-	doc("Reject invalid transport modules."),
+	doc("Ignore invalid transport options."),
 	{ok, _} = ranch:start_listener(misc_bad_transport, 1,
 	{ok, _} = ranch:start_listener(misc_bad_transport, 1,
 		ranch_tcp, [binary, {packet, 4}, <<"garbage">>, raw, backlog], echo_protocol, []),
 		ranch_tcp, [binary, {packet, 4}, <<"garbage">>, raw, backlog], echo_protocol, []),
 	ok.
 	ok.
@@ -272,7 +273,7 @@ tcp_max_connections_and_beyond(_) ->
 	Name = name(),
 	Name = name(),
 	{ok, _} = ranch:start_listener(Name, 1,
 	{ok, _} = ranch:start_listener(Name, 1,
 		ranch_tcp, [{max_connections, 10}],
 		ranch_tcp, [{max_connections, 10}],
-		remove_conn_and_wait_protocol, [{remove, true}]),
+		remove_conn_and_wait_protocol, [{remove, true, 2500}]),
 	Port = ranch:get_port(Name),
 	Port = ranch:get_port(Name),
 	ok = connect_loop(Port, 10, 0),
 	ok = connect_loop(Port, 10, 0),
 	receive after 250 -> ok end,
 	receive after 250 -> ok end,
@@ -283,7 +284,7 @@ tcp_max_connections_and_beyond(_) ->
 	{_, 0} = lists:keyfind(supervisors, 1, Counts),
 	{_, 0} = lists:keyfind(supervisors, 1, Counts),
 	{_, 10} = lists:keyfind(active, 1, Counts),
 	{_, 10} = lists:keyfind(active, 1, Counts),
 	{_, 10} = lists:keyfind(workers, 1, Counts),
 	{_, 10} = lists:keyfind(workers, 1, Counts),
-	ranch:set_protocol_options(Name, [{remove, false}]),
+	ranch:set_protocol_options(Name, [{remove, false, 2500}]),
 	receive after 250 -> ok end,
 	receive after 250 -> ok end,
 	ok = connect_loop(Port, 10, 0),
 	ok = connect_loop(Port, 10, 0),
 	receive after 250 -> ok end,
 	receive after 250 -> ok end,
@@ -315,6 +316,18 @@ tcp_max_connections_infinity(_) ->
 	10 = receive_loop(connected, 1000),
 	10 = receive_loop(connected, 1000),
 	ok = ranch:stop_listener(Name).
 	ok = ranch:stop_listener(Name).
 
 
+tcp_remove_connections(_) ->
+	doc("Ensure that removed connections are only removed once."),
+	Name = name(),
+	{ok, _} = ranch:start_listener(Name, 1,
+		ranch_tcp, [],
+		remove_conn_and_wait_protocol, [{remove, true, 0}]),
+	Port = ranch:get_port(Name),
+	ok = connect_loop(Port, 10, 0),
+	receive after 250 -> ok end,
+	0 = ranch_server:count_connections(Name),
+	ok = ranch:stop_listener(Name).
+
 tcp_set_max_connections(_) ->
 tcp_set_max_connections(_) ->
 	doc("Ensure that changing the max_connections option to a larger value allows for more connections."),
 	doc("Ensure that changing the max_connections option to a larger value allows for more connections."),
 	Name = name(),
 	Name = name(),
@@ -520,7 +533,7 @@ supervisor_conns_alive(_) ->
 		[{'_', [], [{return_trace}]}], [global]),
 		[{'_', [], [{return_trace}]}], [global]),
 	{ok, _} = ranch:start_listener(Name, 1,
 	{ok, _} = ranch:start_listener(Name, 1,
 		ranch_tcp, [],
 		ranch_tcp, [],
-		remove_conn_and_wait_protocol, [{remove, false}]),
+		remove_conn_and_wait_protocol, [{remove, false, 2500}]),
 	%% Get the listener socket
 	%% Get the listener socket
 	LSocket = receive
 	LSocket = receive
 		{trace, _, return_from, {ranch_tcp, listen, 1}, {ok, S}} ->
 		{trace, _, return_from, {ranch_tcp, listen, 1}, {ok, S}} ->

+ 5 - 5
test/remove_conn_and_wait_protocol.erl

@@ -2,13 +2,13 @@
 -behaviour(ranch_protocol).
 -behaviour(ranch_protocol).
 
 
 -export([start_link/4]).
 -export([start_link/4]).
--export([init/2]).
+-export([init/3]).
 
 
-start_link(Ref, _, _, [{remove, MaybeRemove}]) ->
-	Pid = spawn_link(?MODULE, init, [Ref, MaybeRemove]),
+start_link(Ref, _, _, [{remove, MaybeRemove, Timeout}]) ->
+	Pid = spawn_link(?MODULE, init, [Ref, MaybeRemove, Timeout]),
 	{ok, Pid}.
 	{ok, Pid}.
 
 
-init(Ref, MaybeRemove) ->
+init(Ref, MaybeRemove, Timeout) ->
 	ranch:accept_ack(Ref),
 	ranch:accept_ack(Ref),
 	case MaybeRemove of
 	case MaybeRemove of
 		true ->
 		true ->
@@ -16,4 +16,4 @@ init(Ref, MaybeRemove) ->
 		false ->
 		false ->
 			ok
 			ok
 	end,
 	end,
-	receive after 2500 -> ok end.
+	receive after Timeout -> ok end.