diff options
| author | Tim Watson <watson.timothy@gmail.com> | 2012-11-27 12:42:10 +0000 |
|---|---|---|
| committer | Tim Watson <watson.timothy@gmail.com> | 2012-11-27 12:42:10 +0000 |
| commit | 0d91e6d0007ac7c08b3137eb41e0da1a89a2a434 (patch) | |
| tree | d59739283eaeba86d20df7543112bfc699a40a2c /src | |
| parent | f8cec4d22bb841c3796a97b2b42eecb7f0817333 (diff) | |
| download | rabbitmq-server-git-0d91e6d0007ac7c08b3137eb41e0da1a89a2a434.tar.gz | |
tweak for {Mode, Delay} restart types; tweak test timings a little
Diffstat (limited to 'src')
| -rw-r--r-- | src/supervisor2.erl | 29 | ||||
| -rw-r--r-- | src/test_sup.erl | 4 |
2 files changed, 27 insertions, 6 deletions
diff --git a/src/supervisor2.erl b/src/supervisor2.erl index be6319d69a..c5a16a9ff0 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 6a56e64af5..b84acdb442 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) -> |
