[erlang-patches] Re: Supervisor Shutdown
Vance Shipley
vances@REDACTED
Wed Apr 6 02:33:27 CEST 2011
I have implemented a new test case in supervisor_SUITE:sup_terminate/1:
git fetch git@REDACTED:vances/otp.git supervisor_terminate
On Mon, Apr 04, 2011 at 03:32:37PM +0200, Henrik Nord wrote:
} Until then would you be so kind as to complete the patch with tests?
--
-Vance
-------------- next part --------------
>From b317a1512fefbfd9bd1c7f32affd59e61f757ebb Mon Sep 17 00:00:00 2001
From: Vance Shipley <vances@REDACTED>
Date: Tue, 5 Apr 2011 20:30:07 -0400
Subject: [PATCH 21/21] Implemented a test case for new API function terminate/1.
---
lib/stdlib/test/supervisor_SUITE.erl | 35 +++++++++++++++++++++++++++++++--
1 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/lib/stdlib/test/supervisor_SUITE.erl b/lib/stdlib/test/supervisor_SUITE.erl
index 6e927da..5b4d2e1 100644
--- a/lib/stdlib/test/supervisor_SUITE.erl
+++ b/lib/stdlib/test/supervisor_SUITE.erl
@@ -34,8 +34,8 @@
-export([ sup_start_normal/1, sup_start_ignore_init/1,
sup_start_ignore_child/1, sup_start_error_return/1,
sup_start_fail/1, sup_stop_infinity/1,
- sup_stop_timeout/1, sup_stop_brutal_kill/1, child_adm/1,
- child_adm_simple/1, child_specs/1, extra_return/1]).
+ sup_stop_timeout/1, sup_stop_brutal_kill/1, sup_terminate/1,
+ child_adm/1, child_adm_simple/1, child_specs/1, extra_return/1]).
%% Tests concept permanent, transient and temporary
-export([ permanent_normal/1, transient_normal/1,
@@ -78,7 +78,7 @@ groups() ->
sup_start_fail]},
{sup_stop, [],
[sup_stop_infinity, sup_stop_timeout,
- sup_stop_brutal_kill]},
+ sup_stop_brutal_kill, sup_terminate]},
{normal_termination, [],
[permanent_normal, transient_normal, temporary_normal]},
{abnormal_termination, [],
@@ -369,6 +369,35 @@ sup_stop_brutal_kill(Config) when is_list(Config) ->
ok.
%-------------------------------------------------------------------------
+sup_terminate(doc) ->
+ ["Tests that the dynamically added supervisor process, and it's "
+ "children, are terminated gracefully"];
+sup_terminate(suite) -> [];
+
+sup_terminate(Config) when is_list(Config) ->
+ process_flag(trap_exit, true),
+ GChild = {child, {supervisor_1, start_child, []},
+ permanent, 1000, worker, []},
+ StartSpec = {{one_for_one, 2, 3600}, [GChild]},
+ Child = {child, {supervisor, start_link, [?MODULE, {ok, StartSpec}]},
+ transient, infinity, supervisor, []},
+ ?line {ok, Pid} = start({ok, {{simple_one_for_one, 2, 3600}, [Child]}}),
+ ?line {ok, CPid1} = supervisor:start_child(sup_test, []),
+ link(CPid1),
+ ?line [1,1,1,0] = get_child_counts(sup_test),
+ ?line [1,1,0,1] = get_child_counts(CPid1),
+ ?line ok = supervisor:terminate(CPid1),
+ receive
+ {'EXIT', CPid1, shutdown} -> ok;
+ {'EXIT', CPid1, Reason} ->
+ ?line test_server:fail({bad_exit_reason, Reason})
+ after
+ 2000 -> ?line test_server:fail(no_exit_reason)
+ end,
+ ?line [1,0,0,0] = get_child_counts(sup_test),
+ ok.
+
+%-------------------------------------------------------------------------
extra_return(doc) ->
["The start function provided to start a child may "
"return {ok, Pid} or {ok, Pid, Info}, if it returns "
--
1.7.3.2
More information about the erlang-patches
mailing list