Skip to content

Commit

Permalink
Introduced player supervisor which will be a simple_one_for_one super…
Browse files Browse the repository at this point in the history
…visor
  • Loading branch information
dave.mccown committed Dec 28, 2011
1 parent aabbaf4 commit 8748125
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/uno_game_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ init([]) ->
SupFlags = {RestartStrategy, MaxRestarts, MaxSecondsBetweenRestarts},


{ok, {SupFlags, [?CHILD(uno_game, worker, 2000),?CHILD(uno_player, worker, 2000)]}}.
{ok, {SupFlags, [?CHILD(uno_game, worker, 2000),?CHILD(uno_player_sup, supervisor, 2000)]}}.

%%%===================================================================
%%% Internal functions
Expand Down
17 changes: 17 additions & 0 deletions src/uno_player_sup.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-module(uno_player_sup).

-behaviour(supervisor).

-export([start_link/0]).

-export([init/1]).

-include("include/uno_macros.hrl").

-define(SERVER, ?MODULE).

start_link() ->
supervisor:start_link({local, ?SERVER}, ?MODULE, []).

init([]) -> {ok}.

10 changes: 5 additions & 5 deletions test/uno_game_sup_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
-include("include/uno_macros.hrl").
-include_lib("eunit/include/eunit.hrl").

init_should_return_child_specifications_including_four_players_test() ->
{ok, {SupervisorFloags, Children}} = uno_game_sup:init([]),
?assertMatch({one_for_one, 2, 3600}, SupervisorFloags),
init_should_return_child_specifications_including_the_uno_game_and_uno_player_sup_test() ->
{ok, {SupervisorFlags, Children}} = uno_game_sup:init([]),
?assertMatch({one_for_one, 2, 3600}, SupervisorFlags),
?assertMatch([_,_], Children),
[UnoGame, UnoPlayer] = Children,
[UnoGame, UnoPlayerSup] = Children,
?assertEqual(UnoGame, ?CHILD(uno_game, worker, 2000)),
?assertEqual(UnoPlayer, ?CHILD(uno_player, worker, 2000)).
?assertEqual(UnoPlayerSup, ?CHILD(uno_player_sup, supervisor, 2000)).

0 comments on commit 8748125

Please sign in to comment.