aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorjuhlig <[email protected]>2019-02-20 17:41:31 +0100
committerLoïc Hoguin <[email protected]>2019-04-29 13:27:23 +0200
commitdabf62792c2af08c4c6d36177546695356c33b3a (patch)
treefcbe4ac851f9e3c7965e9446d8f68e9855b5fb56 /test
parent012ee216f918b435859616b99d945f4038ce14b9 (diff)
downloadranch-dabf62792c2af08c4c6d36177546695356c33b3a.tar.gz
ranch-dabf62792c2af08c4c6d36177546695356c33b3a.tar.bz2
ranch-dabf62792c2af08c4c6d36177546695356c33b3a.zip
Fix repeated removal of connections
Due to a typo, repeated calls to ranch:remove_connection/1 from a worker process would crash the respective ranch_conns_sup.
Diffstat (limited to 'test')
-rw-r--r--test/acceptor_SUITE.erl15
-rw-r--r--test/remove_conn_and_wait_protocol.erl6
2 files changed, 19 insertions, 2 deletions
diff --git a/test/acceptor_SUITE.erl b/test/acceptor_SUITE.erl
index 7deecbb..3c13d20 100644
--- a/test/acceptor_SUITE.erl
+++ b/test/acceptor_SUITE.erl
@@ -63,6 +63,7 @@ groups() ->
]}, {misc, [
misc_bad_transport,
misc_bad_transport_options,
+ misc_repeated_remove,
misc_info,
misc_info_embedded,
misc_opts_logger,
@@ -291,6 +292,20 @@ misc_opts_logger(_) ->
warning(Format, Args) ->
misc_opts_logger ! {warning, Format, Args}.
+misc_repeated_remove(_) ->
+ doc("Ensure repeated removal of connection does not crash the connection supervisor."),
+ Name = name(),
+ {ok, _} = ranch:start_listener(Name,
+ ranch_tcp, #{},
+ remove_conn_and_wait_protocol, [{remove, 5, 0}]),
+ Port = ranch:get_port(Name),
+ ConnsSup = ranch_server:get_connections_sup(Name),
+ {ok, _} = gen_tcp:connect("localhost", Port, [binary, {active, false}, {packet, raw}]),
+ timer:sleep(1000),
+ ConnsSup = ranch_server:get_connections_sup(Name),
+ true = erlang:is_process_alive(ConnsSup),
+ ok = ranch:stop_listener(Name).
+
misc_wait_for_connections(_) ->
doc("Ensure wait for connections works."),
Name = name(),
diff --git a/test/remove_conn_and_wait_protocol.erl b/test/remove_conn_and_wait_protocol.erl
index 59cedfc..caac41e 100644
--- a/test/remove_conn_and_wait_protocol.erl
+++ b/test/remove_conn_and_wait_protocol.erl
@@ -10,10 +10,12 @@ start_link(Ref, _, _, [{remove, MaybeRemove, Timeout}]) ->
init(Ref, MaybeRemove, Timeout) ->
{ok, _} = ranch:handshake(Ref),
- case MaybeRemove of
+ _ = case MaybeRemove of
true ->
ranch:remove_connection(Ref);
false ->
- ok
+ ok;
+ N ->
+ [ranch:remove_connection(Ref) || _ <- lists:seq(1, N)]
end,
receive after Timeout -> ok end.