From c3eb7832e23aa7cdd3dcfea724c17dc9b54657dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Tue, 15 Nov 2016 17:16:12 +0200 Subject: Add a test for double removal of connections --- test/acceptor_SUITE.erl | 21 +++++++++++++++++---- test/remove_conn_and_wait_protocol.erl | 10 +++++----- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/test/acceptor_SUITE.erl b/test/acceptor_SUITE.erl index 7235420..4b6f022 100644 --- a/test/acceptor_SUITE.erl +++ b/test/acceptor_SUITE.erl @@ -32,6 +32,7 @@ groups() -> tcp_max_connections, tcp_max_connections_and_beyond, tcp_max_connections_infinity, + tcp_remove_connections, tcp_set_max_connections, tcp_set_max_connections_clean, tcp_upgrade, @@ -68,7 +69,7 @@ misc_bad_transport(_) -> ok. misc_bad_transport_options(_) -> - doc("Reject invalid transport modules."), + doc("Ignore invalid transport options."), {ok, _} = ranch:start_listener(misc_bad_transport, 1, ranch_tcp, [binary, {packet, 4}, <<"garbage">>, raw, backlog], echo_protocol, []), ok. @@ -272,7 +273,7 @@ tcp_max_connections_and_beyond(_) -> Name = name(), {ok, _} = ranch:start_listener(Name, 1, 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), ok = connect_loop(Port, 10, 0), receive after 250 -> ok end, @@ -283,7 +284,7 @@ tcp_max_connections_and_beyond(_) -> {_, 0} = lists:keyfind(supervisors, 1, Counts), {_, 10} = lists:keyfind(active, 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, ok = connect_loop(Port, 10, 0), receive after 250 -> ok end, @@ -315,6 +316,18 @@ tcp_max_connections_infinity(_) -> 10 = receive_loop(connected, 1000), 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(_) -> doc("Ensure that changing the max_connections option to a larger value allows for more connections."), Name = name(), @@ -520,7 +533,7 @@ supervisor_conns_alive(_) -> [{'_', [], [{return_trace}]}], [global]), {ok, _} = ranch:start_listener(Name, 1, ranch_tcp, [], - remove_conn_and_wait_protocol, [{remove, false}]), + remove_conn_and_wait_protocol, [{remove, false, 2500}]), %% Get the listener socket LSocket = receive {trace, _, return_from, {ranch_tcp, listen, 1}, {ok, S}} -> diff --git a/test/remove_conn_and_wait_protocol.erl b/test/remove_conn_and_wait_protocol.erl index 6c8206c..db688ff 100644 --- a/test/remove_conn_and_wait_protocol.erl +++ b/test/remove_conn_and_wait_protocol.erl @@ -2,13 +2,13 @@ -behaviour(ranch_protocol). -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}. -init(Ref, MaybeRemove) -> +init(Ref, MaybeRemove, Timeout) -> ranch:accept_ack(Ref), case MaybeRemove of true -> @@ -16,4 +16,4 @@ init(Ref, MaybeRemove) -> false -> ok end, - receive after 2500 -> ok end. + receive after Timeout -> ok end. -- cgit v1.2.3