summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Sackman <matthew@rabbitmq.com>2010-07-29 15:42:50 +0100
committerMatthew Sackman <matthew@rabbitmq.com>2010-07-29 15:42:50 +0100
commitd9500ff2ca2f86d50bfd3be449bf74bff428be06 (patch)
tree6369d09d526419cb1024dc1b4f6e8d967e945d14
parent9ea8ba57e5f66c53d591914cb9dcf171ebf1a79b (diff)
downloadrabbitmq-server-d9500ff2ca2f86d50bfd3be449bf74bff428be06.tar.gz
Extend test coverage of delayed restart to simple case and fix exposed bug
-rw-r--r--src/supervisor2.erl4
-rw-r--r--src/test_sup.erl27
2 files changed, 22 insertions, 9 deletions
diff --git a/src/supervisor2.erl b/src/supervisor2.erl
index ff0bac83..fb4c9b02 100644
--- a/src/supervisor2.erl
+++ b/src/supervisor2.erl
@@ -342,8 +342,8 @@ handle_call(which_children, _From, State) ->
{reply, Resp, State}.
-handle_cast({delayed_restart, {RestartType, Reason, Child}},
- State = #state{children = [Child]}) when ?is_simple(State) ->
+handle_cast({delayed_restart, {RestartType, Reason, Child}}, State)
+ when ?is_simple(State) ->
{ok, NState} = do_restart(RestartType, Reason, Child, State),
{noreply, NState};
handle_cast({delayed_restart, {RestartType, Reason, Child}}, State)
diff --git a/src/test_sup.erl b/src/test_sup.erl
index 655370a1..f2450aaf 100644
--- a/src/test_sup.erl
+++ b/src/test_sup.erl
@@ -37,7 +37,19 @@
init/1, start_child/0, run_child/0]).
test_supervisor_delayed_restart() ->
- {ok, SupPid} = start_link(),
+ passed = test_supervisor_delayed_restart(
+ simple_one_for_one_terminate,
+ fun (SupPid) ->
+ {ok, _ChildPid} = supervisor2:start_child(SupPid, []),
+ ok
+ end),
+ passed = test_supervisor_delayed_restart(
+ one_for_one,
+ fun (_SupPid) -> ok end).
+
+test_supervisor_delayed_restart(RestartStrategy, PostStartLinkFun) ->
+ {ok, SupPid} = start_link(RestartStrategy),
+ ok = PostStartLinkFun(SupPid),
ok = ping_child(SupPid),
ok = exit_child(SupPid),
timer:sleep(10),
@@ -51,16 +63,16 @@ test_supervisor_delayed_restart() ->
rabbit_misc:unlink_and_capture_exit(SupPid),
passed.
-start_link() ->
- supervisor2:start_link(?MODULE, []).
+start_link(RestartStrategy) ->
+ supervisor2:start_link(?MODULE, [RestartStrategy]).
-init([]) ->
- {ok, {{one_for_one, 1, 1},
+init([RestartStrategy]) ->
+ {ok, {{RestartStrategy, 1, 1},
[{test, {test_sup, start_child, []}, {permanent, 1},
16#ffffffff, worker, [test_sup]}]}}.
start_child() ->
- {ok, spawn_link(fun run_child/0)}.
+ {ok, proc_lib:spawn_link(fun run_child/0)}.
ping_child(SupPid) ->
Ref = make_ref(),
@@ -74,7 +86,8 @@ exit_child(SupPid) ->
ok.
get_child_pid(SupPid) ->
- [{test, ChildPid, worker, [test_sup]}] = supervisor2:which_children(SupPid),
+ [{_Id, ChildPid, worker, [test_sup]}] =
+ supervisor2:which_children(SupPid),
ChildPid.
run_child() ->