From 55d56a1108a92b53633629b76458e830fcc99e35 Mon Sep 17 00:00:00 2001 From: juhlig Date: Wed, 5 Jun 2019 14:20:12 +0200 Subject: Fix timing issues in shutdown test suite --- test/shutdown_SUITE.erl | 21 +++++++++++---------- 1 file 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. -- cgit v1.2.3