diff options
| author | Matthew Sackman <matthew@rabbitmq.com> | 2010-07-29 15:42:50 +0100 |
|---|---|---|
| committer | Matthew Sackman <matthew@rabbitmq.com> | 2010-07-29 15:42:50 +0100 |
| commit | 406f55288a51903e53cc1f61394337be858fcbec (patch) | |
| tree | 6369d09d526419cb1024dc1b4f6e8d967e945d14 | |
| parent | 865565f1907452ffd55adce2cfa7a52bbe5afd9a (diff) | |
| download | rabbitmq-server-git-406f55288a51903e53cc1f61394337be858fcbec.tar.gz | |
Extend test coverage of delayed restart to simple case and fix exposed bug
| -rw-r--r-- | src/supervisor2.erl | 4 | ||||
| -rw-r--r-- | src/test_sup.erl | 27 |
2 files changed, 22 insertions, 9 deletions
diff --git a/src/supervisor2.erl b/src/supervisor2.erl index ff0bac835d..fb4c9b02bf 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 655370a11c..f2450aafc2 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() -> |
