diff options
author | j.uhlig <[email protected]> | 2018-05-04 16:23:27 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2018-05-16 17:16:56 +0200 |
commit | 963f53942f1106771e91a018ac9ad46e3bc6a777 (patch) | |
tree | 6f733090ec39b55616b2ccdea266090dbfb8b365 /test | |
parent | 16762abdcffa53834d44e22eb4d26ef699c89fc2 (diff) | |
download | ranch-963f53942f1106771e91a018ac9ad46e3bc6a777.tar.gz ranch-963f53942f1106771e91a018ac9ad46e3bc6a777.tar.bz2 ranch-963f53942f1106771e91a018ac9ad46e3bc6a777.zip |
Ensure listener restart with changed TransOpts
Diffstat (limited to 'test')
-rw-r--r-- | test/acceptor_SUITE.erl | 38 | ||||
-rw-r--r-- | test/ranch_ct_hook.erl | 5 |
2 files changed, 43 insertions, 0 deletions
diff --git a/test/acceptor_SUITE.erl b/test/acceptor_SUITE.erl index e441b51..4918642 100644 --- a/test/acceptor_SUITE.erl +++ b/test/acceptor_SUITE.erl @@ -62,6 +62,7 @@ groups() -> ]}, {supervisor, [ connection_type_supervisor, connection_type_supervisor_separate_from_connection, + supervisor_changed_options_restart, supervisor_clean_child_restart, supervisor_clean_conns_sup_restart, supervisor_clean_restart, @@ -799,6 +800,36 @@ connection_type_supervisor_separate_from_connection(_) -> {'EXIT', _} = begin catch ranch:get_port(Name) end, ok. +supervisor_changed_options_restart(_) -> + doc("Ensure that a listener is restarted with changed transport options."), + Name = name(), + %% Start a listener using send_timeout as option change marker. + {ok, ListenerSupPid1} = ranch:start_listener(Name, + ranch_tcp, [{send_timeout, 300000}], + echo_protocol, []), + %% Ensure send_timeout is really set to initial value. + {ok, [{send_timeout, 300000}]} + = inet:getopts(do_get_listener_socket(ListenerSupPid1), [send_timeout]), + %% Change send_timeout option. + ok = ranch:suspend_listener(Name), + ok = ranch:set_transport_options(Name, [{send_timeout, 300001}]), + ok = ranch:resume_listener(Name), + %% Ensure send_timeout is really set to the changed value. + {ok, [{send_timeout, 300001}]} + = inet:getopts(do_get_listener_socket(ListenerSupPid1), [send_timeout]), + %% Crash the listener_sup process, allow a short time for restart to succeed. + exit(ListenerSupPid1, kill), + timer:sleep(1000), + %% Obtain pid of restarted listener_sup process. + [ListenerSupPid2] = [Pid || {{ranch_listener_sup, Ref}, Pid, supervisor, _} + <- supervisor:which_children(ranch_sup), Ref =:= Name], + %% Ensure send_timeout is still set to the changed value. + {ok, [{send_timeout, 300001}]} + = inet:getopts(do_get_listener_socket(ListenerSupPid2), [send_timeout]), + ok = ranch:stop_listener(Name), + {'EXIT', _} = begin catch ranch:get_port(Name) end, + ok. + supervisor_clean_child_restart(Config) -> case code:is_module_native(?MODULE) of true -> doc("This test uses tracing and is not compatible with native code."); @@ -1034,3 +1065,10 @@ clean_traces() -> after 0 -> ok end. + +do_get_listener_socket(ListenerSupPid) -> + [AcceptorsSupPid] = [Pid || {ranch_acceptors_sup, Pid, supervisor, _} + <- supervisor:which_children(ListenerSupPid)], + {links, Links} = erlang:process_info(AcceptorsSupPid, links), + [LSocket] = [P || P <- Links, is_port(P)], + LSocket. diff --git a/test/ranch_ct_hook.erl b/test/ranch_ct_hook.erl index 183cdf5..07f89df 100644 --- a/test/ranch_ct_hook.erl +++ b/test/ranch_ct_hook.erl @@ -17,6 +17,11 @@ -export([init/2]). init(_, _) -> + %% Allow a more relaxed restart intensity because + %% some tests will cause quick restarts of several + %% ranch_sup children. + application:set_env(ranch, ranch_sup_intensity, 10), + application:set_env(ranch, ranch_sup_period, 1), ct_helper:start([ranch]), ct_helper:make_certs_in_ets(), error_logger:add_report_handler(ct_helper_error_h), |