aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjuhlig <[email protected]>2019-06-05 14:20:12 +0200
committerjuhlig <[email protected]>2019-06-05 14:20:12 +0200
commit55d56a1108a92b53633629b76458e830fcc99e35 (patch)
tree29a8a56f2d0f26d51ce052a63748b204812e960a
parentb1169f6d3b5688c655be54756a480cceadded223 (diff)
downloadranch-55d56a1108a92b53633629b76458e830fcc99e35.tar.gz
ranch-55d56a1108a92b53633629b76458e830fcc99e35.tar.bz2
ranch-55d56a1108a92b53633629b76458e830fcc99e35.zip
Fix timing issues in shutdown test suite
-rw-r--r--test/shutdown_SUITE.erl21
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.