summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Watson <watson.timothy@gmail.com>2012-11-27 12:42:10 +0000
committerTim Watson <watson.timothy@gmail.com>2012-11-27 12:42:10 +0000
commit721de630fdd3e7817ece0e788475a0081fcbc749 (patch)
treed59739283eaeba86d20df7543112bfc699a40a2c
parentbbe8ed714286772fed5c7326b6e819284888de53 (diff)
downloadrabbitmq-server-721de630fdd3e7817ece0e788475a0081fcbc749.tar.gz
tweak for {Mode, Delay} restart types; tweak test timings a little
-rw-r--r--src/supervisor2.erl29
-rw-r--r--src/test_sup.erl4
2 files changed, 27 insertions, 6 deletions
diff --git a/src/supervisor2.erl b/src/supervisor2.erl
index be6319d6..c5a16a9f 100644
--- a/src/supervisor2.erl
+++ b/src/supervisor2.erl
@@ -338,8 +338,12 @@ init_dynamic(_State, StartSpec) ->
start_children(Children, SupName) -> start_children(Children, [], SupName).
start_children([Child|Chs], NChildren, SupName) ->
+ Restart = case Child#child.restart_type of
+ A when is_atom(A) -> A;
+ {N, _} when is_atom(N) -> N
+ end,
case do_start_child(SupName, Child) of
- {ok, undefined} when Child#child.restart_type =:= temporary ->
+ {ok, undefined} when Restart =:= temporary ->
start_children(Chs, NChildren, SupName);
{ok, Pid} ->
start_children(Chs, [Child#child{pid = Pid}|NChildren], SupName);
@@ -394,9 +398,13 @@ do_start_child_i(M, F, A) ->
handle_call({start_child, EArgs}, _From, State) when ?is_simple(State) ->
Child = hd(State#state.children),
#child{mfargs = {M, F, A}} = Child,
+ Restart = case Child#child.restart_type of
+ Name when is_atom(Name) -> Name;
+ {Type, _} when is_atom(Type) -> Type
+ end,
Args = A ++ EArgs,
case do_start_child_i(M, F, Args) of
- {ok, undefined} when Child#child.restart_type =:= temporary ->
+ {ok, undefined} when Restart =:= temporary ->
{reply, {ok, undefined}, State};
{ok, Pid} ->
NState = save_dynamic_child(Child#child.restart_type, Pid, Args, State),
@@ -630,7 +638,7 @@ handle_info({delayed_restart, {RestartType, Reason, Child}}, State) ->
{value, Child1} ->
{ok, NState} = do_restart(RestartType, Reason, Child1, State),
{noreply, NState};
- _ ->
+ What ->
{noreply, State}
end;
@@ -806,7 +814,7 @@ do_restart(temporary, Reason, Child, State) ->
{ok, NState}.
do_restart_delay({RestartType, Delay}, Reason, Child, State) ->
- case restart(Child, State) of
+ case restart1(Child, State) of
{ok, NState} ->
{ok, NState};
{terminate, NState} ->
@@ -816,6 +824,19 @@ do_restart_delay({RestartType, Delay}, Reason, Child, State) ->
{ok, state_del_child(Child, NState)}
end.
+restart1(Child, State) ->
+ case add_restart(State) of
+ {ok, NState} ->
+ restart(NState#state.strategy, Child, NState);
+ {terminate, _NState} ->
+ %% we've reached the max restart intensity, but the
+ %% add_restart will have added to the restarts
+ %% field. Given we don't want to die here, we need to go
+ %% back to the old restarts field otherwise we'll never
+ %% attempt to restart later.
+ {terminate, State}
+ end.
+
del_child_and_maybe_shutdown(intrinsic, Child, State) ->
{shutdown, state_del_child(Child, State)};
del_child_and_maybe_shutdown({intrinsic, _Delay}, Child, State) ->
diff --git a/src/test_sup.erl b/src/test_sup.erl
index 6a56e64a..b84acdb4 100644
--- a/src/test_sup.erl
+++ b/src/test_sup.erl
@@ -50,7 +50,7 @@ test_supervisor_delayed_restart(SupPid) ->
ok = exit_child(SupPid),
timer:sleep(100),
timeout = ping_child(SupPid),
- timer:sleep(1010),
+ timer:sleep(1100),
ok = ping_child(SupPid),
passed.
@@ -73,7 +73,7 @@ ping_child(SupPid) ->
Ref = make_ref(),
with_child_pid(SupPid, fun(ChildPid) -> ChildPid ! {ping, Ref, self()} end),
receive {pong, Ref} -> ok
- after 1000 -> timeout
+ after 1100 -> timeout
end.
exit_child(SupPid) ->