diff options
Diffstat (limited to 'test/shutdown_SUITE.erl')
-rw-r--r-- | test/shutdown_SUITE.erl | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/test/shutdown_SUITE.erl b/test/shutdown_SUITE.erl index 3cef65a..c97d277 100644 --- a/test/shutdown_SUITE.erl +++ b/test/shutdown_SUITE.erl @@ -33,8 +33,7 @@ brutal_kill(_) -> ranch_tcp, #{shutdown => brutal_kill}, echo_protocol, []), Port = ranch:get_port(Name), - {ok, _} = gen_tcp:connect("localhost", Port, []), - receive after 100 -> ok end, + ok = do_connect_and_ping(Port), ListenerSupChildren = supervisor:which_children(ListenerSup), {_, ConnsSupSup, _, _} = lists:keyfind(ranch_conns_sup_sup, 1, ListenerSupChildren), [Pid] = do_get_conn_pids(ConnsSupSup), @@ -53,8 +52,7 @@ infinity(_) -> ranch_tcp, #{shutdown => infinity}, echo_protocol, []), Port = ranch:get_port(Name), - {ok, _} = gen_tcp:connect("localhost", Port, []), - receive after 100 -> ok end, + ok = do_connect_and_ping(Port), ListenerSupChildren = supervisor:which_children(ListenerSup), {_, ConnsSupSup, _, _} = lists:keyfind(ranch_conns_sup_sup, 1, ListenerSupChildren), [Pid] = do_get_conn_pids(ConnsSupSup), @@ -75,8 +73,7 @@ infinity_trap_exit(_) -> ranch_tcp, #{shutdown => infinity}, trap_exit_protocol, []), Port = ranch:get_port(Name), - {ok, _} = gen_tcp:connect("localhost", Port, []), - receive after 100 -> ok end, + ok = do_connect_and_ping(Port), ListenerSupChildren = supervisor:which_children(ListenerSup), {_, ConnsSupSup, _, _} = lists:keyfind(ranch_conns_sup_sup, 1, ListenerSupChildren), [Pid] = do_get_conn_pids(ConnsSupSup), @@ -104,8 +101,7 @@ timeout(_) -> ranch_tcp, #{shutdown => 500}, echo_protocol, []), Port = ranch:get_port(Name), - {ok, _} = gen_tcp:connect("localhost", Port, []), - receive after 100 -> ok end, + ok = do_connect_and_ping(Port), ListenerSupChildren = supervisor:which_children(ListenerSup), {_, ConnsSupSup, _, _} = lists:keyfind(ranch_conns_sup_sup, 1, ListenerSupChildren), [Pid] = do_get_conn_pids(ConnsSupSup), @@ -126,8 +122,7 @@ timeout_trap_exit(_) -> ranch_tcp, #{shutdown => 500}, trap_exit_protocol, []), Port = ranch:get_port(Name), - {ok, _} = gen_tcp:connect("localhost", Port, []), - receive after 100 -> ok end, + ok = do_connect_and_ping(Port), ListenerSupChildren = supervisor:which_children(ListenerSup), {_, ConnsSupSup, _, _} = lists:keyfind(ranch_conns_sup_sup, 1, ListenerSupChildren), [Pid] = do_get_conn_pids(ConnsSupSup), @@ -154,3 +149,9 @@ do_get_conn_pids(ConnsSupSup) -> ConnChildren = lists:flatten( [supervisor:which_children(ConnsSup) || ConnsSup <- ConnsSups]), [ConnPid || {_, ConnPid, _, _} <- ConnChildren]. + +do_connect_and_ping(Port) -> + {ok, Conn} = gen_tcp:connect("localhost", Port, [binary, {active, false}, {packet, raw}]), + ok = gen_tcp:send(Conn, <<"PING">>), + {ok, <<"PING">>} = gen_tcp:recv(Conn, 4, 1000), + ok. |