diff options
| author | Simon MacMullen <simon@rabbitmq.com> | 2011-08-09 13:12:37 +0100 |
|---|---|---|
| committer | Simon MacMullen <simon@rabbitmq.com> | 2011-08-09 13:12:37 +0100 |
| commit | 2a7d16833d40ef6b007fc4d9048b7a9ff46908e0 (patch) | |
| tree | 4f4233bb7ba51eabc5c2be558b70f62506be5987 /src | |
| parent | 1ddad291fa6a5932db9cb1b4dca27419d48cab22 (diff) | |
| download | rabbitmq-server-git-2a7d16833d40ef6b007fc4d9048b7a9ff46908e0.tar.gz | |
Blow up if we're asked for simple_one_for_one, more tests, try to handle Mod:init/1 returning ignore.
Diffstat (limited to 'src')
| -rw-r--r-- | src/mirrored_supervisor.erl | 47 | ||||
| -rw-r--r-- | src/mirrored_supervisor_tests.erl | 27 |
2 files changed, 56 insertions, 18 deletions
diff --git a/src/mirrored_supervisor.erl b/src/mirrored_supervisor.erl index bed24cfd53..3ecff1efea 100644 --- a/src/mirrored_supervisor.erl +++ b/src/mirrored_supervisor.erl @@ -228,22 +228,36 @@ %%---------------------------------------------------------------------------- start_link(Group, Mod, Args) -> - start_link0([], Group, Mod, Args). + start_link0([], Group, init(Mod, Args)). start_link({local, SupName}, Group, Mod, Args) -> - start_link0([{local, SupName}], Group, Mod, Args); + start_link0([{local, SupName}], Group, init(Mod, Args)); start_link({global, _SupName}, _Group, _Mod, _Args) -> error(badarg). -start_link0(Prefix, Group, Mod, Args) -> +start_link0(Prefix, Group, Init) -> case apply(?SUPERVISOR, start_link, - Prefix ++ [?MODULE, {overall, Group, Mod, Args}]) of + Prefix ++ [?MODULE, {overall, Group, Init}]) of {ok, Pid} -> call(Pid, {init, Pid}), {ok, Pid}; Other -> Other end. +init(Mod, Args) -> + case Mod:init(Args) of + Init = {ok, {Restart, _ChildSpecs}} -> + case Restart of + {Bad, _, _} when Bad =:= simple_one_for_one orelse + Bad =:= simple_one_for_one_terminate -> + error(badarg); + _ -> + Init + end; + ignore -> + ignore + end. + start_child(Sup, ChildSpec) -> call(Sup, {start_child, ChildSpec}). delete_child(Sup, Name) -> call(Sup, {delete_child, Name}). restart_child(Sup, Name) -> call(Sup, {msg, restart_child, [Name]}). @@ -270,16 +284,21 @@ start_internal(Group, ChildSpecs) -> %%---------------------------------------------------------------------------- -init({overall, Group, Mod, Args}) -> - {ok, {Restart, ChildSpecs}} = Mod:init(Args), - Delegate = {delegate, {?SUPERVISOR, start_link, - [?MODULE, {delegate, Restart}]}, - temporary, 16#ffffffff, supervisor, [?SUPERVISOR]}, - Mirroring = {mirroring, {?MODULE, start_internal, [Group, ChildSpecs]}, - permanent, 16#ffffffff, worker, [?MODULE]}, - %% Important: Delegate MUST start after Mirroring, see comment in - %% handle_info('DOWN', ...) below - {ok, {{one_for_all, 0, 1}, [Mirroring, Delegate]}}; +init({overall, Group, Init}) -> + case Init of + {ok, {Restart, ChildSpecs}} -> + Delegate = {delegate, {?SUPERVISOR, start_link, + [?MODULE, {delegate, Restart}]}, + temporary, 16#ffffffff, supervisor, [?SUPERVISOR]}, + Mirroring = {mirroring, {?MODULE, start_internal, + [Group, ChildSpecs]}, + permanent, 16#ffffffff, worker, [?MODULE]}, + %% Important: Delegate MUST start after Mirroring, see comment in + %% handle_info('DOWN', ...) below + {ok, {{one_for_all, 0, 1}, [Mirroring, Delegate]}}; + ignore -> + ignore + end; init({delegate, Restart}) -> {ok, {Restart, []}}; diff --git a/src/mirrored_supervisor_tests.erl b/src/mirrored_supervisor_tests.erl index f3d7f1aca5..e5a4747db4 100644 --- a/src/mirrored_supervisor_tests.erl +++ b/src/mirrored_supervisor_tests.erl @@ -40,6 +40,7 @@ all_tests() -> passed = test_anonymous_supervisors(), passed = test_no_migration_on_shutdown(), passed = test_start_idempotence(), + passed = test_unsupported(), passed. %% Simplest test @@ -142,6 +143,23 @@ test_start_idempotence() -> {error, {already_started, Pid}} = ?MS:start_child(a, CS) end, [a]). +test_unsupported() -> + try + ?MS:start_link({global, foo}, get_group(group), ?MODULE, + {sup, one_for_one, []}), + exit(no_global) + catch error:badarg -> + ok + end, + try + ?MS:start_link({local, foo}, get_group(group), ?MODULE, + {sup, simple_one_for_one, []}), + exit(no_sofo) + catch error:badarg -> + ok + end, + passed. + %% --------------------------------------------------------------------------- with_sups(Fun, Sups) -> @@ -165,10 +183,11 @@ start_sup(Name, Group) -> start_sup({Name, []}, Group). start_sup0(anon, Group, ChildSpecs) -> - ?MS:start_link(Group, ?MODULE, {sup, ChildSpecs}); + ?MS:start_link(Group, ?MODULE, {sup, one_for_one, ChildSpecs}); start_sup0(Name, Group, ChildSpecs) -> - ?MS:start_link({local, Name}, Group, ?MODULE, {sup, ChildSpecs}). + ?MS:start_link({local, Name}, Group, ?MODULE, + {sup, one_for_one, ChildSpecs}). childspec(Id) -> {Id, {?MODULE, start_gs, [Id]}, transient, 16#ffffffff, worker, [?MODULE]}. @@ -221,8 +240,8 @@ kill_wait(Pid) -> %% Dumb gen_server we can supervise %% --------------------------------------------------------------------------- -init({sup, ChildSpecs}) -> - {ok, {{one_for_one, 0, 1}, ChildSpecs}}; +init({sup, Strategy, ChildSpecs}) -> + {ok, {{Strategy, 0, 1}, ChildSpecs}}; init(server) -> {ok, state}. |
