aboutsummaryrefslogtreecommitdiffstats
path: root/test/shutdown_SUITE.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2015-08-20 21:36:34 +0200
committerLoïc Hoguin <[email protected]>2015-08-20 21:36:34 +0200
commitd30408b2e8c14c0e56ce997f5aff0010c03cef0b (patch)
tree91182bcca1d67fa3ec8de89f43513be6f8bd0d5c /test/shutdown_SUITE.erl
parent300e5f39227f6206d3003dbdb52b15e4791f29fc (diff)
downloadranch-d30408b2e8c14c0e56ce997f5aff0010c03cef0b.tar.gz
ranch-d30408b2e8c14c0e56ce997f5aff0010c03cef0b.tar.bz2
ranch-d30408b2e8c14c0e56ce997f5aff0010c03cef0b.zip
More test suites refactoring
They are now properly documented and the listener name is automatically specified thanks to a new ct_helper function.
Diffstat (limited to 'test/shutdown_SUITE.erl')
-rw-r--r--test/shutdown_SUITE.erl38
1 files changed, 21 insertions, 17 deletions
diff --git a/test/shutdown_SUITE.erl b/test/shutdown_SUITE.erl
index 97963d5..212d14c 100644
--- a/test/shutdown_SUITE.erl
+++ b/test/shutdown_SUITE.erl
@@ -1,4 +1,4 @@
-%% Copyright (c) 2013, Loïc Hoguin <[email protected]>
+%% Copyright (c) 2013-2015, Loïc Hoguin <[email protected]>
%%
%% Permission to use, copy, modify, and/or distribute this software for any
%% purpose with or without fee is hereby granted, provided that the above
@@ -16,6 +16,7 @@
-compile(export_all).
-import(ct_helper, [doc/1]).
+-import(ct_helper, [name/0]).
%% ct.
@@ -25,7 +26,8 @@ all() ->
%% Tests.
brutal_kill(_) ->
- Name = brutal_kill,
+ doc("Shutdown Ranch listener with shutdown option set to brutal_kill."),
+ Name = name(),
{ok, ListenerSup} = ranch:start_listener(Name, 1,
ranch_tcp, [{port, 0}, {shutdown, brutal_kill}],
echo_protocol, []),
@@ -33,8 +35,7 @@ brutal_kill(_) ->
{ok, _} = gen_tcp:connect("localhost", Port, []),
receive after 100 -> ok end,
ListenerSupChildren = supervisor:which_children(ListenerSup),
- {_, ConnsSup, _, _}
- = lists:keyfind(ranch_conns_sup, 1, ListenerSupChildren),
+ {_, ConnsSup, _, _} = lists:keyfind(ranch_conns_sup, 1, ListenerSupChildren),
[{_, Pid, _, _}] = supervisor:which_children(ConnsSup),
true = is_process_alive(Pid),
ok = ranch:stop_listener(Name),
@@ -45,7 +46,8 @@ brutal_kill(_) ->
ok.
infinity(_) ->
- Name = infinity,
+ doc("Shutdown Ranch listener with shutdown option set to infinity."),
+ Name = name(),
{ok, ListenerSup} = ranch:start_listener(Name, 1,
ranch_tcp, [{port, 0}, {shutdown, infinity}],
echo_protocol, []),
@@ -53,8 +55,7 @@ infinity(_) ->
{ok, _} = gen_tcp:connect("localhost", Port, []),
receive after 100 -> ok end,
ListenerSupChildren = supervisor:which_children(ListenerSup),
- {_, ConnsSup, _, _}
- = lists:keyfind(ranch_conns_sup, 1, ListenerSupChildren),
+ {_, ConnsSup, _, _} = lists:keyfind(ranch_conns_sup, 1, ListenerSupChildren),
[{_, Pid, _, _}] = supervisor:which_children(ConnsSup),
true = is_process_alive(Pid),
ok = ranch:stop_listener(Name),
@@ -65,7 +66,10 @@ infinity(_) ->
ok.
infinity_trap_exit(_) ->
- Name = infinity_trap_exit,
+ doc("Shutdown Ranch listener with shutdown option set to infinity "
+ "and protocol process trapping exits. The listener must not stop "
+ "until the protocol process terminates."),
+ Name = name(),
{ok, ListenerSup} = ranch:start_listener(Name, 1,
ranch_tcp, [{port, 0}, {shutdown, infinity}],
trap_exit_protocol, []),
@@ -73,8 +77,7 @@ infinity_trap_exit(_) ->
{ok, _} = gen_tcp:connect("localhost", Port, []),
receive after 100 -> ok end,
ListenerSupChildren = supervisor:which_children(ListenerSup),
- {_, ConnsSup, _, _}
- = lists:keyfind(ranch_conns_sup, 1, ListenerSupChildren),
+ {_, ConnsSup, _, _} = lists:keyfind(ranch_conns_sup, 1, ListenerSupChildren),
[{_, Pid, _, _}] = supervisor:which_children(ConnsSup),
true = is_process_alive(Pid),
%% This call will block infinitely.
@@ -93,9 +96,9 @@ infinity_trap_exit(_) ->
false = is_process_alive(SpawnPid),
ok.
-%% Same as infinity because the protocol doesn't trap exits.
timeout(_) ->
- Name = timeout,
+ doc("Shutdown Ranch listener with shutdown option set to 500ms."),
+ Name = name(),
{ok, ListenerSup} = ranch:start_listener(Name, 1,
ranch_tcp, [{port, 0}, {shutdown, 500}],
echo_protocol, []),
@@ -103,8 +106,7 @@ timeout(_) ->
{ok, _} = gen_tcp:connect("localhost", Port, []),
receive after 100 -> ok end,
ListenerSupChildren = supervisor:which_children(ListenerSup),
- {_, ConnsSup, _, _}
- = lists:keyfind(ranch_conns_sup, 1, ListenerSupChildren),
+ {_, ConnsSup, _, _} = lists:keyfind(ranch_conns_sup, 1, ListenerSupChildren),
[{_, Pid, _, _}] = supervisor:which_children(ConnsSup),
true = is_process_alive(Pid),
ok = ranch:stop_listener(Name),
@@ -115,7 +117,10 @@ timeout(_) ->
ok.
timeout_trap_exit(_) ->
- Name = timeout_trap_exit,
+ doc("Shutdown Ranch listener with shutdown option set to 500ms "
+ "and protocol process trapping exits. The listener will only stop "
+ "after the 500ms timeout."),
+ Name = name(),
{ok, ListenerSup} = ranch:start_listener(Name, 1,
ranch_tcp, [{port, 0}, {shutdown, 500}],
trap_exit_protocol, []),
@@ -123,8 +128,7 @@ timeout_trap_exit(_) ->
{ok, _} = gen_tcp:connect("localhost", Port, []),
receive after 100 -> ok end,
ListenerSupChildren = supervisor:which_children(ListenerSup),
- {_, ConnsSup, _, _}
- = lists:keyfind(ranch_conns_sup, 1, ListenerSupChildren),
+ {_, ConnsSup, _, _} = lists:keyfind(ranch_conns_sup, 1, ListenerSupChildren),
[{_, Pid, _, _}] = supervisor:which_children(ConnsSup),
true = is_process_alive(Pid),
%% This call will block for the duration of the shutdown.