From b400e34386ec0dc3f290da6c4671d7d0621d2fe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Wed, 4 Jul 2018 10:57:05 +0200 Subject: Better distinguish between Ranch and socket options A map should now be used when specifying transport options that contain more than just socket options. It is still possible to pass a list of socket options directly as a convenience. The ack_timeout is renamed to handshake_timeout when specified as a map. This corresponds to the new function ranch:handshake/1,2 that will be favored in Ranch 2.0. Specifying Ranch-specific options via the proplist will no longer be possible starting from Ranch 2.0. --- test/acceptor_SUITE.erl | 193 +++++++++++++++++++++++++++++++----------------- test/shutdown_SUITE.erl | 10 +-- 2 files changed, 130 insertions(+), 73 deletions(-) (limited to 'test') diff --git a/test/acceptor_SUITE.erl b/test/acceptor_SUITE.erl index 0be5d40..50f0ce2 100644 --- a/test/acceptor_SUITE.erl +++ b/test/acceptor_SUITE.erl @@ -83,30 +83,34 @@ groups() -> misc_bad_transport(_) -> doc("Reject invalid transport modules."), {error, badarg} = ranch:start_listener(misc_bad_transport, - bad_transport, [], echo_protocol, []), + bad_transport, #{}, + echo_protocol, []), ok. misc_bad_transport_options(_) -> doc("Ignore invalid transport options."), - {ok, _} = ranch:start_listener(misc_bad_transport, - ranch_tcp, [binary, {packet, 4}, <<"garbage">>, raw, backlog], echo_protocol, []), + {ok, _} = ranch:start_listener(misc_bad_transport_options, + ranch_tcp, [binary, {packet, 4}, <<"garbage">>, raw, backlog], + echo_protocol, []), ok. misc_info(_) -> doc("Information about listeners."), %% Open a listener with a few connections. {ok, Pid1} = ranch:start_listener({misc_info, tcp}, - ranch_tcp, [{num_acceptors, 1}], + ranch_tcp, #{num_acceptors => 1}, remove_conn_and_wait_protocol, [{remove, true, 2500}]), Port1 = ranch:get_port({misc_info, tcp}), %% Open a few more listeners with different arguments. {ok, Pid2} = ranch:start_listener({misc_info, act}, - ranch_tcp, [{num_acceptors, 2}], active_echo_protocol, {}), + ranch_tcp, #{num_acceptors => 2}, + active_echo_protocol, {}), Port2 = ranch:get_port({misc_info, act}), ranch:set_max_connections({misc_info, act}, infinity), Opts = ct_helper:get_certs_from_ets(), {ok, Pid3} = ranch:start_listener({misc_info, ssl}, - ranch_ssl, [{num_acceptors, 3}|Opts], echo_protocol, [{}]), + ranch_ssl, #{num_acceptors => 3, socket_opts => Opts}, + echo_protocol, [{}]), Port3 = ranch:get_port({misc_info, ssl}), %% Open 5 connections, 3 removed from the count. {ok, _} = gen_tcp:connect("localhost", Port1, [binary, {active, false}, {packet, raw}]), @@ -125,12 +129,11 @@ misc_info(_) -> {status, _}, {ip, _}, {port, Port2}, - {num_acceptors, 2}, {max_connections, infinity}, %% Option was modified. {active_connections, 0}, {all_connections, 0}, {transport, ranch_tcp}, - {transport_options, [{num_acceptors, 2}]}, + {transport_options, #{num_acceptors := 2}}, {protocol, active_echo_protocol}, {protocol_options, {}} ]}, @@ -139,12 +142,11 @@ misc_info(_) -> {status, _}, {ip, _}, {port, Port3}, - {num_acceptors, 3}, {max_connections, 1024}, {active_connections, 0}, {all_connections, 0}, {transport, ranch_ssl}, - {transport_options, [{num_acceptors, 3}|Opts]}, + {transport_options, #{num_acceptors := 3, socket_opts := Opts}}, {protocol, echo_protocol}, {protocol_options, [{}]} ]}, @@ -153,12 +155,11 @@ misc_info(_) -> {status, _}, {ip, _}, {port, Port1}, - {num_acceptors, 1}, {max_connections, 1024}, {active_connections, 2}, {all_connections, 5}, {transport, ranch_tcp}, - {transport_options, [{num_acceptors, 1}]}, + {transport_options, #{num_acceptors := 1}}, {protocol, remove_conn_and_wait_protocol}, {protocol_options, [{remove, false, 2500}]} %% Option was modified. ]} @@ -177,15 +178,20 @@ misc_info_embedded(_) -> doc("Information about listeners in embedded mode."), {ok, SupPid} = embedded_sup:start_link(), %% Open a listener with a few connections. - {ok, Pid1} = embedded_sup:start_listener(SupPid, {misc_info_embedded, tcp}, ranch_tcp, [{num_acceptors, 1}], remove_conn_and_wait_protocol, [{remove, true, 2500}]), + {ok, Pid1} = embedded_sup:start_listener(SupPid, {misc_info_embedded, tcp}, + ranch_tcp, #{num_acceptors => 1}, + remove_conn_and_wait_protocol, [{remove, true, 2500}]), Port1 = ranch:get_port({misc_info_embedded, tcp}), %% Open a few more listeners with different arguments. - {ok, Pid2} = embedded_sup:start_listener(SupPid, {misc_info_embedded, act}, ranch_tcp, [{num_acceptors, 2}], active_echo_protocol, {}), + {ok, Pid2} = embedded_sup:start_listener(SupPid, {misc_info_embedded, act}, + ranch_tcp, #{num_acceptors => 2}, + active_echo_protocol, {}), Port2 = ranch:get_port({misc_info_embedded, act}), ranch:set_max_connections({misc_info_embedded, act}, infinity), Opts = ct_helper:get_certs_from_ets(), {ok, Pid3} = embedded_sup:start_listener(SupPid, {misc_info_embedded, ssl}, - ranch_ssl, [{num_acceptors, 3}|Opts], echo_protocol, [{}]), + ranch_ssl, #{num_acceptors => 3, socket_opts => Opts}, + echo_protocol, [{}]), Port3 = ranch:get_port({misc_info_embedded, ssl}), %% Open 5 connections, 3 removed from the count. {ok, _} = gen_tcp:connect("localhost", Port1, [binary, {active, false}, {packet, raw}]), @@ -204,12 +210,11 @@ misc_info_embedded(_) -> {status, _}, {ip, _}, {port, Port2}, - {num_acceptors, 2}, {max_connections, infinity}, %% Option was modified. {active_connections, 0}, {all_connections, 0}, {transport, ranch_tcp}, - {transport_options, [{num_acceptors, 2}]}, + {transport_options, #{num_acceptors := 2}}, {protocol, active_echo_protocol}, {protocol_options, {}} ]}, @@ -218,12 +223,11 @@ misc_info_embedded(_) -> {status, _}, {ip, _}, {port, Port3}, - {num_acceptors, 3}, {max_connections, 1024}, {active_connections, 0}, {all_connections, 0}, {transport, ranch_ssl}, - {transport_options, [{num_acceptors, 3}|Opts]}, + {transport_options, #{num_acceptors := 3, socket_opts := Opts}}, {protocol, echo_protocol}, {protocol_options, [{}]} ]}, @@ -232,12 +236,11 @@ misc_info_embedded(_) -> {status, _}, {ip, _}, {port, Port1}, - {num_acceptors, 1}, {max_connections, 1024}, {active_connections, 2}, {all_connections, 5}, {transport, ranch_tcp}, - {transport_options, [{num_acceptors, 1}]}, + {transport_options, #{num_acceptors := 1}}, {protocol, remove_conn_and_wait_protocol}, {protocol_options, [{remove, false, 2500}]} %% Option was modified. ]} @@ -288,7 +291,7 @@ misc_wait_for_connections(_) -> Pid2GE = do_create_waiter(Self, Name, '>=', 2), Pid2EQ = do_create_waiter(Self, Name, '==', 2), {ok, _} = ranch:start_listener(Name, - ranch_tcp, [{num_acceptors, 1}], + ranch_tcp, #{num_acceptors => 1}, echo_protocol, []), Port = ranch:get_port(Name), %% Create some connections, ensure that waiters respond. @@ -351,7 +354,8 @@ ssl_accept_error(_) -> Name = name(), Opts = ct_helper:get_certs_from_ets(), {ok, ListenerSup} = ranch:start_listener(Name, - ranch_ssl, [{num_acceptors, 1}|Opts], echo_protocol, []), + ranch_ssl, #{num_acceptors => 1, socket_opts => Opts}, + echo_protocol, []), Port = ranch:get_port(Name), ListenerSupChildren = supervisor:which_children(ListenerSup), {_, AcceptorsSup, _, _} = lists:keyfind(ranch_acceptors_sup, 1, ListenerSupChildren), @@ -368,7 +372,9 @@ ssl_accept_socket(_) -> Name = name(), Opts = ct_helper:get_certs_from_ets(), {ok, S} = ssl:listen(0, [binary, {active, false}, {packet, raw}, {reuseaddr, true}|Opts]), - {ok, _} = ranch:start_listener(Name, ranch_ssl, [{socket, S}], echo_protocol, []), + {ok, _} = ranch:start_listener(Name, + ranch_ssl, #{socket => S}, + echo_protocol, []), Port = ranch:get_port(Name), {ok, Socket} = ssl:connect("localhost", Port, [binary, {active, false}, {packet, raw}]), ok = ssl:send(Socket, <<"TCP Ranch is working!">>), @@ -383,7 +389,9 @@ ssl_active_echo(_) -> doc("Ensure that active mode works with SSL transport."), Name = name(), Opts = ct_helper:get_certs_from_ets(), - {ok, _} = ranch:start_listener(Name, ranch_ssl, Opts, active_echo_protocol, []), + {ok, _} = ranch:start_listener(Name, + ranch_ssl, Opts, + active_echo_protocol, []), Port = ranch:get_port(Name), {ok, Socket} = ssl:connect("localhost", Port, [binary, {active, false}, {packet, raw}]), ok = ssl:send(Socket, <<"SSL Ranch is working!">>), @@ -398,7 +406,9 @@ ssl_echo(_) -> doc("Ensure that passive mode works with SSL transport."), Name = name(), Opts = ct_helper:get_certs_from_ets(), - {ok, _} = ranch:start_listener(Name, ranch_ssl, Opts, echo_protocol, []), + {ok, _} = ranch:start_listener(Name, + ranch_ssl, Opts, + echo_protocol, []), Port = ranch:get_port(Name), {ok, Socket} = ssl:connect("localhost", Port, [binary, {active, false}, {packet, raw}]), ok = ssl:send(Socket, <<"SSL Ranch is working!">>), @@ -421,7 +431,9 @@ do_ssl_sni_echo() -> doc("Ensure that SNI works with SSL transport."), Name = name(), Opts = ct_helper:get_certs_from_ets(), - {ok, _} = ranch:start_listener(Name, ranch_ssl, [{sni_hosts, [{"localhost", Opts}]}], echo_protocol, []), + {ok, _} = ranch:start_listener(Name, + ranch_ssl, [{sni_hosts, [{"localhost", Opts}]}], + echo_protocol, []), Port = ranch:get_port(Name), {ok, Socket} = ssl:connect("localhost", Port, [binary, {active, false}, {packet, raw}]), ok = ssl:send(Socket, <<"SSL Ranch is working!">>), @@ -444,7 +456,9 @@ do_ssl_sni_fail() -> doc("Ensure that connection fails when host is not in SNI list."), Name = name(), Opts = ct_helper:get_certs_from_ets(), - {ok, _} = ranch:start_listener(Name, ranch_ssl, [{sni_hosts, [{"pouet", Opts}]}], echo_protocol, []), + {ok, _} = ranch:start_listener(Name, + ranch_ssl, [{sni_hosts, [{"pouet", Opts}]}], + echo_protocol, []), Port = ranch:get_port(Name), {error, _} = ssl:connect("localhost", Port, [binary, {active, false}, {packet, raw}]), ok = ranch:stop_listener(Name), @@ -456,7 +470,9 @@ ssl_graceful(_) -> doc("Ensure suspending and resuming of listeners does not kill active connections."), Name = name(), Opts = ct_helper:get_certs_from_ets(), - {ok, _} = ranch:start_listener(Name, ranch_ssl, Opts, echo_protocol, []), + {ok, _} = ranch:start_listener(Name, + ranch_ssl, Opts, + echo_protocol, []), Port = ranch:get_port(Name), %% Make sure connections with a fresh listener work. running = ranch:get_status(Name), @@ -465,7 +481,7 @@ ssl_graceful(_) -> ok = ssl:send(Socket1, <<"SSL with fresh listener">>), {ok, <<"SSL with fresh listener">>} = ssl:recv(Socket1, 23, 1000), %% Make sure transport options cannot be changed on a running listener. - {error, running} = ranch:set_transport_options(Name, [{port, Port}|Opts]), + {error, running} = ranch:set_transport_options(Name, #{socket_opts => [{port, Port}|Opts]}), %% Suspend listener, make sure established connections keep running. ok = ranch:suspend_listener(Name), suspended = ranch:get_status(Name), @@ -475,7 +491,7 @@ ssl_graceful(_) -> {error, econnrefused} = ssl:connect("localhost", Port, [binary, {active, false}, {packet, raw}]), %% Make sure transport options can be changed when listener is suspended. - ok = ranch:set_transport_options(Name, [{port, Port}|Opts]), + ok = ranch:set_transport_options(Name, #{socket_opts => [{port, Port}|Opts]}), %% Resume listener, make sure connections can be established again. ok = ranch:resume_listener(Name), running = ranch:get_status(Name), @@ -484,7 +500,7 @@ ssl_graceful(_) -> ok = ssl:send(Socket2, <<"SSL with resumed listener">>), {ok, <<"SSL with resumed listener">>} = ssl:recv(Socket2, 25, 1000), %% Make sure transport options cannot be changed on resumed listener. - {error, running} = ranch:set_transport_options(Name, [{port, Port}|Opts]), + {error, running} = ranch:set_transport_options(Name, #{socket_opts => [{port, Port}|Opts]}), ok = ranch:stop_listener(Name), {error, closed} = ssl:recv(Socket1, 0, 1000), {error, closed} = ssl:recv(Socket2, 0, 1000), @@ -495,7 +511,9 @@ ssl_accept_ack(_) -> doc("Ensure accept_ack works with SSL transport."), Name = name(), Opts = ct_helper:get_certs_from_ets(), - {ok, _} = ranch:start_listener(Name, ranch_ssl, Opts, accept_ack_protocol, []), + {ok, _} = ranch:start_listener(Name, + ranch_ssl, Opts, + accept_ack_protocol, []), Port = ranch:get_port(Name), {ok, Socket} = ssl:connect("localhost", Port, [binary, {active, false}, {packet, raw}]), ok = ssl:send(Socket, <<"SSL transport accept_ack is working!">>), @@ -509,7 +527,9 @@ ssl_getopts_capability(_) -> doc("Ensure getopts/2 capability."), Name=name(), Opts=ct_helper:get_certs_from_ets(), - {ok, _}=ranch:start_listener(Name, ranch_ssl, Opts, transport_capabilities_protocol, []), + {ok, _} = ranch:start_listener(Name, + ranch_ssl, Opts, + transport_capabilities_protocol, []), Port=ranch:get_port(Name), {ok, Socket}=ssl:connect("localhost", Port, [binary, {active, false}, {packet, raw}]), ok=ssl:send(Socket, <<"getopts/2">>), @@ -531,7 +551,9 @@ do_ssl_getstat_capability() -> doc("Ensure getstat/{1,2} capability."), Name=name(), Opts=ct_helper:get_certs_from_ets(), - {ok, _}=ranch:start_listener(Name, ranch_ssl, Opts, transport_capabilities_protocol, []), + {ok, _} = ranch:start_listener(Name, + ranch_ssl, Opts, + transport_capabilities_protocol, []), Port=ranch:get_port(Name), {ok, Socket}=ssl:connect("localhost", Port, [binary, {active, false}, {packet, raw}]), ok=ssl:send(Socket, <<"getstat/1">>), @@ -547,10 +569,13 @@ ssl_error_eaddrinuse(_) -> doc("Ensure that failure due to an eaddrinuse returns a compact readable error."), Name = name(), Opts = ct_helper:get_certs_from_ets(), - {ok, _} = ranch:start_listener(Name, ranch_ssl, Opts, active_echo_protocol, []), + {ok, _} = ranch:start_listener(Name, + ranch_ssl, Opts, + active_echo_protocol, []), Port = ranch:get_port(Name), {error, eaddrinuse} = ranch:start_listener({Name, fails}, - ranch_ssl, [{port, Port}|Opts], active_echo_protocol, []), + ranch_ssl, [{port, Port}|Opts], + active_echo_protocol, []), ok = ranch:stop_listener(Name), %% Make sure the listener stopped. {'EXIT', _} = begin catch ranch:get_port(Name) end, @@ -558,7 +583,9 @@ ssl_error_eaddrinuse(_) -> ssl_error_no_cert(_) -> doc("Ensure that failure due to missing certificate returns a compact readable error."), - {error, no_cert} = ranch:start_listener(name(), ranch_ssl, [], active_echo_protocol, []), + {error, no_cert} = ranch:start_listener(name(), + ranch_ssl, #{}, + active_echo_protocol, []), ok. ssl_error_eacces(_) -> @@ -570,7 +597,8 @@ ssl_error_eacces(_) -> Name = name(), Opts = ct_helper:get_certs_from_ets(), {error, eacces} = ranch:start_listener(Name, - ranch_ssl, [{port, 283}|Opts], active_echo_protocol, []), + ranch_ssl, [{port, 283}|Opts], + active_echo_protocol, []), ok end. @@ -580,7 +608,9 @@ tcp_accept_socket(_) -> doc("Ensure that listener can use an externally opened TCP listen socket."), Name = name(), {ok, S} = gen_tcp:listen(0, [binary, {active, false}, {packet, raw}, {reuseaddr, true}]), - {ok, _} = ranch:start_listener(Name, ranch_tcp, [{socket, S}], echo_protocol, []), + {ok, _} = ranch:start_listener(Name, + ranch_tcp, #{socket => S}, + echo_protocol, []), Port = ranch:get_port(Name), {ok, Socket} = gen_tcp:connect("localhost", Port, [binary, {active, false}, {packet, raw}]), ok = gen_tcp:send(Socket, <<"TCP Ranch is working!">>), @@ -594,7 +624,9 @@ tcp_accept_socket(_) -> tcp_active_echo(_) -> doc("Ensure that active mode works with TCP transport."), Name = name(), - {ok, _} = ranch:start_listener(Name, ranch_tcp, [], active_echo_protocol, []), + {ok, _} = ranch:start_listener(Name, + ranch_tcp, #{}, + active_echo_protocol, []), Port = ranch:get_port(Name), {ok, Socket} = gen_tcp:connect("localhost", Port, [binary, {active, false}, {packet, raw}]), ok = gen_tcp:send(Socket, <<"TCP Ranch is working!">>), @@ -608,7 +640,9 @@ tcp_active_echo(_) -> tcp_echo(_) -> doc("Ensure that passive mode works with TCP transport."), Name = name(), - {ok, _} = ranch:start_listener(Name, ranch_tcp, [], echo_protocol, []), + {ok, _} = ranch:start_listener(Name, + ranch_tcp, #{}, + echo_protocol, []), Port = ranch:get_port(Name), {ok, Socket} = gen_tcp:connect("localhost", Port, [binary, {active, false}, {packet, raw}]), ok = gen_tcp:send(Socket, <<"TCP Ranch is working!">>), @@ -622,7 +656,9 @@ tcp_echo(_) -> tcp_graceful(_) -> doc("Ensure suspending and resuming of listeners does not kill active connections."), Name = name(), - {ok, _} = ranch:start_listener(Name, ranch_tcp, [], echo_protocol, []), + {ok, _} = ranch:start_listener(Name, + ranch_tcp, #{}, + echo_protocol, []), Port = ranch:get_port(Name), %% Make sure connections with a fresh listener work. running = ranch:get_status(Name), @@ -660,7 +696,9 @@ tcp_graceful(_) -> tcp_accept_ack(_) -> doc("Ensure accept_ack works with TCP transport."), Name = name(), - {ok, _} = ranch:start_listener(Name, ranch_tcp, [], accept_ack_protocol, []), + {ok, _} = ranch:start_listener(Name, + ranch_tcp, #{}, + accept_ack_protocol, []), Port = ranch:get_port(Name), {ok, Socket} = gen_tcp:connect("localhost", Port, [binary, {active, false}, {packet, raw}]), ok = gen_tcp:send(Socket, <<"TCP transport accept_ack is working!">>), @@ -674,7 +712,9 @@ tcp_inherit_options(_) -> doc("Ensure TCP options are inherited in the protocol."), Name = name(), Opts = [{nodelay, false}, {send_timeout_close, false}], - {ok, _} = ranch:start_listener(Name, ranch_tcp, Opts, check_tcp_options, [{pid, self()} | Opts]), + {ok, _} = ranch:start_listener(Name, + ranch_tcp, Opts, + check_tcp_options, [{pid, self()} | Opts]), Port = ranch:get_port(Name), {ok, Socket} = gen_tcp:connect("localhost", Port, [binary, {active, true}, {packet, raw}]), receive checked -> ok after 1000 -> error(timeout) end, @@ -685,7 +725,7 @@ tcp_max_connections(_) -> doc("Ensure the max_connections option actually limits connections."), Name = name(), {ok, _} = ranch:start_listener(Name, - ranch_tcp, [{max_connections, 10}, {num_acceptors, 1}], + ranch_tcp, #{max_connections => 10, num_acceptors => 1}, notify_and_wait_protocol, [{msg, connected}, {pid, self()}]), Port = ranch:get_port(Name), ok = connect_loop(Port, 11, 150), @@ -698,7 +738,7 @@ tcp_max_connections_and_beyond(_) -> doc("Ensure the max_connections option works when connections are removed from the count."), Name = name(), {ok, _} = ranch:start_listener(Name, - ranch_tcp, [{max_connections, 10}, {num_acceptors, 1}], + ranch_tcp, #{max_connections => 10, num_acceptors => 1}, remove_conn_and_wait_protocol, [{remove, true, 2500}]), Port = ranch:get_port(Name), ok = connect_loop(Port, 10, 0), @@ -725,7 +765,7 @@ tcp_max_connections_infinity(_) -> doc("Set the max_connections option from 10 to infinity and back to 10."), Name = name(), {ok, _} = ranch:start_listener(Name, - ranch_tcp, [{max_connections, 10}, {num_acceptors, 1}], + ranch_tcp, #{max_connections => 10, num_acceptors => 1}, notify_and_wait_protocol, [{msg, connected}, {pid, self()}]), Port = ranch:get_port(Name), ok = connect_loop(Port, 20, 0), @@ -746,7 +786,7 @@ tcp_remove_connections(_) -> doc("Ensure that removed connections are only removed once."), Name = name(), {ok, _} = ranch:start_listener(Name, - ranch_tcp, [], + ranch_tcp, #{}, remove_conn_and_wait_protocol, [{remove, true, 0}]), Port = ranch:get_port(Name), ok = connect_loop(Port, 10, 0), @@ -758,7 +798,7 @@ tcp_set_max_connections(_) -> doc("Ensure that changing the max_connections option to a larger value allows for more connections."), Name = name(), {ok, _} = ranch:start_listener(Name, - ranch_tcp, [{max_connections, 10}, {num_acceptors, 1}], + ranch_tcp, #{max_connections => 10, num_acceptors => 1}, notify_and_wait_protocol, [{msg, connected}, {pid, self()}]), Port = ranch:get_port(Name), ok = connect_loop(Port, 20, 0), @@ -779,9 +819,9 @@ tcp_set_max_connections_clean(Config) -> do_tcp_set_max_connections_clean(_) -> doc("Ensure that setting max_connections does not crash any process."), Name = name(), - {ok, ListSupPid} = ranch:start_listener(Name, ranch_tcp, - [{max_connections, 4}], - notify_and_wait_protocol, [{msg, connected}, {pid, self()}]), + {ok, ListSupPid} = ranch:start_listener(Name, + ranch_tcp, #{max_connections => 4}, + notify_and_wait_protocol, [{msg, connected}, {pid, self()}]), Children = supervisor:which_children(ListSupPid), {_, AccSupPid, _, _} = lists:keyfind(ranch_acceptors_sup, 1, Children), 1 = erlang:trace(ListSupPid, true, [procs]), @@ -805,7 +845,9 @@ do_tcp_set_max_connections_clean(_) -> tcp_getopts_capability(_) -> doc("Ensure getopts/2 capability."), Name=name(), - {ok, _}=ranch:start_listener(Name, ranch_tcp, [], transport_capabilities_protocol, []), + {ok, _}=ranch:start_listener(Name, + ranch_tcp, #{}, + transport_capabilities_protocol, []), Port=ranch:get_port(Name), {ok, Socket}=gen_tcp:connect("localhost", Port, [binary, {active, false}, {packet, raw}]), ok=gen_tcp:send(Socket, <<"getopts/2">>), @@ -818,7 +860,9 @@ tcp_getopts_capability(_) -> tcp_getstat_capability(_) -> doc("Ensure getstat/{1,2} capability."), Name=name(), - {ok, _}=ranch:start_listener(Name, ranch_tcp, [], transport_capabilities_protocol, []), + {ok, _}=ranch:start_listener(Name, + ranch_tcp, #{}, + transport_capabilities_protocol, []), Port=ranch:get_port(Name), {ok, Socket}=gen_tcp:connect("localhost", Port, [binary, {active, false}, {packet, raw}]), ok=gen_tcp:send(Socket, <<"getstat/1">>), @@ -834,7 +878,7 @@ tcp_upgrade(_) -> doc("Ensure that protocol options can be updated."), Name = name(), {ok, _} = ranch:start_listener(Name, - ranch_tcp, [], + ranch_tcp, #{}, notify_and_wait_protocol, [{msg, connected}, {pid, self()}]), Port = ranch:get_port(Name), ok = connect_loop(Port, 1, 0), @@ -847,10 +891,13 @@ tcp_upgrade(_) -> tcp_error_eaddrinuse(_) -> doc("Ensure that failure due to an eaddrinuse returns a compact readable error."), Name = name(), - {ok, _} = ranch:start_listener(Name, ranch_tcp, [], active_echo_protocol, []), + {ok, _} = ranch:start_listener(Name, + ranch_tcp, #{}, + active_echo_protocol, []), Port = ranch:get_port(Name), {error, eaddrinuse} = ranch:start_listener({Name, fails}, - ranch_tcp, [{port, Port}], active_echo_protocol, []), + ranch_tcp, [{port, Port}], + active_echo_protocol, []), ok = ranch:stop_listener(Name), %% Make sure the listener stopped. {'EXIT', _} = begin catch ranch:get_port(Name) end, @@ -864,7 +911,8 @@ tcp_error_eacces(_) -> doc("Ensure that failure due to an eacces returns a compact readable error."), Name = name(), {error, eacces} = ranch:start_listener(Name, - ranch_tcp, [{port, 283}], active_echo_protocol, []), + ranch_tcp, [{port, 283}], + active_echo_protocol, []), ok end. @@ -874,7 +922,7 @@ connection_type_supervisor(_) -> doc("The supervisor connection type must be reflected in the specifications."), Name = name(), {ok, _} = ranch:start_listener(Name, - ranch_tcp, [{connection_type, supervisor}], + ranch_tcp, #{connection_type => supervisor}, echo_protocol, []), Port = ranch:get_port(Name), {ok, Socket} = gen_tcp:connect("localhost", Port, [binary, {active, false}, {packet, raw}]), @@ -892,7 +940,7 @@ connection_type_supervisor_separate_from_connection(_) -> doc("The supervisor connection type allows separate supervised and connection processes."), Name = name(), {ok, _} = ranch:start_listener(Name, - ranch_tcp, [{connection_type, supervisor}], + ranch_tcp, #{connection_type => supervisor}, supervisor_separate, []), Port = ranch:get_port(Name), {ok, Socket} = gen_tcp:connect("localhost", Port, [binary, {active, false}, {packet, raw}]), @@ -951,7 +999,8 @@ do_supervisor_clean_child_restart(_) -> 1 = erlang:trace_pattern({ranch_tcp, listen, 1}, [{'_', [], [{return_trace}]}], [global]), {ok, Pid} = ranch:start_listener(Name, - ranch_tcp, [{num_acceptors, 1}], echo_protocol, []), + ranch_tcp, #{num_acceptors => 1}, + echo_protocol, []), %% Trace supervisor spawns. 1 = erlang:trace(Pid, true, [procs, set_on_spawn]), ConnsSup = ranch_server:get_connections_sup(Name), @@ -987,7 +1036,8 @@ supervisor_clean_conns_sup_restart(_) -> "the ranch_server process."), Name = name(), {ok, _} = ranch:start_listener(Name, - ranch_tcp, [], echo_protocol, []), + ranch_tcp, #{}, + echo_protocol, []), Server = erlang:whereis(ranch_server), ServerMonRef = erlang:monitor(process, Server), %% Exit because Name already registered and is alive. @@ -1013,7 +1063,8 @@ do_supervisor_clean_restart(_) -> Name = name(), NumAcc = 4, {ok, Pid} = ranch:start_listener(Name, - ranch_tcp, [{num_acceptors, NumAcc}], echo_protocol, []), + ranch_tcp, #{num_acceptors => NumAcc}, + echo_protocol, []), %% Trace supervisor spawns. 1 = erlang:trace(Pid, true, [procs, set_on_spawn]), ConnsSup0 = ranch_server:get_connections_sup(Name), @@ -1053,7 +1104,7 @@ do_supervisor_conns_alive(_) -> 1 = erlang:trace_pattern({ranch_tcp, listen, 1}, [{'_', [], [{return_trace}]}], [global]), {ok, _} = ranch:start_listener(Name, - ranch_tcp, [], + ranch_tcp, #{}, remove_conn_and_wait_protocol, [{remove, false, 2500}]), %% Get the listener socket LSocket = receive @@ -1079,7 +1130,9 @@ do_supervisor_conns_alive(_) -> supervisor_protocol_start_link_crash(_) -> doc("Ensure a protocol start crash does not kill all connections."), Name = name(), - {ok, _} = ranch:start_listener(Name, ranch_tcp, [], crash_protocol, []), + {ok, _} = ranch:start_listener(Name, + ranch_tcp, #{}, + crash_protocol, []), ConnsSup = ranch_server:get_connections_sup(Name), Port = ranch:get_port(Name), {ok, _} = gen_tcp:connect("localhost", Port, [binary, {active, true}, {packet, raw}]), @@ -1100,7 +1153,9 @@ do_supervisor_server_recover_state(_) -> _ = erlang:trace(new, true, [call]), 1 = erlang:trace_pattern({ranch_server, init, 1}, [{'_', [], [{return_trace}]}], [global]), - {ok, _} = ranch:start_listener(Name, ranch_tcp, [], echo_protocol, []), + {ok, _} = ranch:start_listener(Name, + ranch_tcp, #{}, + echo_protocol, []), ConnsSup = ranch_server:get_connections_sup(Name), ServerPid = erlang:whereis(ranch_server), {monitors, Monitors} = erlang:process_info(ServerPid, monitors), @@ -1125,7 +1180,9 @@ supervisor_unexpected_message(_) -> doc("Ensure the connections supervisor stays alive when it receives " "an unexpected message."), Name = name(), - {ok, ListenerPid} = ranch:start_listener(Name, ranch_tcp, [], echo_protocol, []), + {ok, ListenerPid} = ranch:start_listener(Name, + ranch_tcp, #{}, + echo_protocol, []), Port = ranch:get_port(Name), {ok, Socket} = gen_tcp:connect("localhost", Port, [binary, {active, false}, {packet, raw}]), ok = gen_tcp:send(Socket, <<"TCP Ranch is working!">>), diff --git a/test/shutdown_SUITE.erl b/test/shutdown_SUITE.erl index d46e223..249458e 100644 --- a/test/shutdown_SUITE.erl +++ b/test/shutdown_SUITE.erl @@ -30,7 +30,7 @@ brutal_kill(_) -> doc("Shutdown Ranch listener with shutdown option set to brutal_kill."), Name = name(), {ok, ListenerSup} = ranch:start_listener(Name, - ranch_tcp, [{port, 0}, {shutdown, brutal_kill}], + ranch_tcp, #{shutdown => brutal_kill}, echo_protocol, []), Port = ranch:get_port(Name), {ok, _} = gen_tcp:connect("localhost", Port, []), @@ -50,7 +50,7 @@ infinity(_) -> doc("Shutdown Ranch listener with shutdown option set to infinity."), Name = name(), {ok, ListenerSup} = ranch:start_listener(Name, - ranch_tcp, [{port, 0}, {shutdown, infinity}], + ranch_tcp, #{shutdown => infinity}, echo_protocol, []), Port = ranch:get_port(Name), {ok, _} = gen_tcp:connect("localhost", Port, []), @@ -72,7 +72,7 @@ infinity_trap_exit(_) -> "until the protocol process terminates."), Name = name(), {ok, ListenerSup} = ranch:start_listener(Name, - ranch_tcp, [{port, 0}, {shutdown, infinity}], + ranch_tcp, #{shutdown => infinity}, trap_exit_protocol, []), Port = ranch:get_port(Name), {ok, _} = gen_tcp:connect("localhost", Port, []), @@ -101,7 +101,7 @@ timeout(_) -> doc("Shutdown Ranch listener with shutdown option set to 500ms."), Name = name(), {ok, ListenerSup} = ranch:start_listener(Name, - ranch_tcp, [{port, 0}, {shutdown, 500}], + ranch_tcp, #{shutdown => 500}, echo_protocol, []), Port = ranch:get_port(Name), {ok, _} = gen_tcp:connect("localhost", Port, []), @@ -123,7 +123,7 @@ timeout_trap_exit(_) -> "after the 500ms timeout."), Name = name(), {ok, ListenerSup} = ranch:start_listener(Name, - ranch_tcp, [{port, 0}, {shutdown, 500}], + ranch_tcp, #{shutdown => 500}, trap_exit_protocol, []), Port = ranch:get_port(Name), {ok, _} = gen_tcp:connect("localhost", Port, []), -- cgit v1.2.3