Added more tests & functionality. (failing join table, create_table_test with force)
This commit is contained in:
parent
654aa837dd
commit
391af1a96a
2 changed files with 31 additions and 7 deletions
|
@ -1,7 +1,7 @@
|
||||||
-module(ggs_coordinator).
|
-module(ggs_coordinator).
|
||||||
|
|
||||||
%% API Exports
|
%% API Exports
|
||||||
-export([start_link/0, stop/1]).
|
-export([start_link/0, stop/1, join_table/1, create_table/1]).
|
||||||
|
|
||||||
%% gen_server callback exports
|
%% gen_server callback exports
|
||||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
|
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
|
||||||
|
@ -19,13 +19,14 @@ start_link() ->
|
||||||
stop(Reason) ->
|
stop(Reason) ->
|
||||||
gen_server:cast(ggs_coordinator, {stop, Reason}).
|
gen_server:cast(ggs_coordinator, {stop, Reason}).
|
||||||
|
|
||||||
%% @doc Joins table with specified token
|
%% @doc Joins table with specified token, returns {error, no_such_table}
|
||||||
join_table(_Token) ->
|
%% if the specified table token does not exist
|
||||||
ggs_logger:not_implemented().
|
join_table(Token) ->
|
||||||
|
gen_server:call(ggs_coordinator, {join_table, Token}).
|
||||||
|
|
||||||
%% @doc Create a new table
|
%% @doc Create a new table, return {error, Reason} or {ok, TableToken}
|
||||||
create_table(_Params) ->
|
create_table(Params) ->
|
||||||
ggs_logger:not_implemented().
|
gen_server:call(ggs_coordinator, {create_table, Params}).
|
||||||
|
|
||||||
%% @doc This is the first function run by a newly created players.
|
%% @doc This is the first function run by a newly created players.
|
||||||
%% Generates a unique token that we use to identify the player.
|
%% Generates a unique token that we use to identify the player.
|
||||||
|
@ -49,6 +50,12 @@ remove_player(_From, _Player) ->
|
||||||
init([]) ->
|
init([]) ->
|
||||||
{ok, ok}.
|
{ok, ok}.
|
||||||
|
|
||||||
|
handle_call({join_table, Table}, From, State) ->
|
||||||
|
{reply, {error, no_such_table}, State};
|
||||||
|
|
||||||
|
handle_call({create_table, {force, TID}}, From, State) ->
|
||||||
|
{reply, {ok, TID}, State};
|
||||||
|
|
||||||
handle_call(_Message, _From, State) ->
|
handle_call(_Message, _From, State) ->
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
|
|
|
@ -14,3 +14,20 @@ stop_test() ->
|
||||||
ggs_coordinator:stop("Terminate now"), % Send stop message
|
ggs_coordinator:stop("Terminate now"), % Send stop message
|
||||||
timer:sleep(100), % Wait for cleaning..
|
timer:sleep(100), % Wait for cleaning..
|
||||||
?assert((erlang:process_info(Coord) == undefined)). % Did it stop?
|
?assert((erlang:process_info(Coord) == undefined)). % Did it stop?
|
||||||
|
|
||||||
|
join_bad_table_test() ->
|
||||||
|
{ok, _Coord} = ggs_coordinator:start_link(),
|
||||||
|
Response = ggs_coordinator:join_table("Nonexistant table"),
|
||||||
|
ggs_coordinator:stop(""),
|
||||||
|
timer:sleep(100),
|
||||||
|
?assert(Response == {error, no_such_table}).
|
||||||
|
|
||||||
|
|
||||||
|
create_table_test() ->
|
||||||
|
{ok, _Coord} = ggs_coordinator:start_link(),
|
||||||
|
% Forcibly create a table. This functionality should be disabled
|
||||||
|
% in the production system, but is pretty nice for testing.
|
||||||
|
Response = ggs_coordinator:create_table({force, 1337}),
|
||||||
|
ggs_coordinator:stop(""),
|
||||||
|
timer:sleep(100),
|
||||||
|
?assert(Response == {ok, 1337}).
|
||||||
|
|
Reference in a new issue