Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid node on Henchmen test #31

Merged
merged 2 commits into from
Jul 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion relx.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{release,
{beam_olympics, "0.0.1"},
{beam_olympics, "1.0.0"},
[ kernel
, stdlib
, beam_olympics
Expand Down
4 changes: 3 additions & 1 deletion src/bo_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ init(noargs) -> {ok, #{}}.
-spec handle_call
(stats, {pid(), term()}, state()) ->
{reply, bo_players_repo:stats(), state()};
({signup, bo_players:name()}, {pid(), term()}, state()) ->
({signup, term()}, {pid(), term()}, state()) ->
{reply, {ok, bo_task:task()} | {error, conflict}, state()};
({task, bo_players:name()}, {pid(), term()}, state()) ->
{reply, {ok, bo_task:task()}
Expand All @@ -51,6 +51,8 @@ init(noargs) -> {ok, #{}}.
| {error, ended | forbidden | notfound}, state()}.
handle_call(stats, _From, State) ->
{reply, bo_players_repo:stats(), State};
handle_call({signup, Data}, _From, State) when not is_binary(Data) ->
{reply, {error, invalid}, State};
handle_call({signup, PlayerName}, {From, _}, State) ->
Node = node(From),
try bo_players_repo:signup(PlayerName, Node) of
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/bo_henchmen.erl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ kills_siblings(Fun) ->
doesnt_kill_remotes(Fun) ->
Harry = Fun(),
[Node | _] = nodes(),
Victim = spawn(Node, fun() -> receive x -> ok end end),
Victim = spawn(Node, timer, sleep, [3000]),
try
true = is_process_alive(Harry),
true = rpc:pinfo(Victim) /= undefined,
Expand Down
27 changes: 22 additions & 5 deletions test/bo_player_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

-export([all/0]).
-export([init_per_suite/1, end_per_suite/1]).
-export([register_ok/1, wrong_node/1, duplicated_username/1]).
-export([register_ok/1, wrong_node/1, duplicated_username/1, wrong_username/1]).

-type config() :: proplists:proplist().

-spec all() -> [atom()].
all() -> [register_ok, duplicated_username, wrong_node].
all() -> [register_ok, duplicated_username, wrong_node, wrong_username].

-spec init_per_suite(config()) -> config().
init_per_suite(Config) ->
Expand Down Expand Up @@ -80,13 +80,13 @@ duplicated_username(_Config) ->
{ok, Client2} = bo_test_client:start(duplicated_username2),

try
ct:comment("User ok is created in node1"),
ct:comment("User dup is created in node1"),
{ok, _Task} = bo_test_client:signup(Client1, <<"dup">>),

ct:comment("User ok can't be created in node1"),
ct:comment("User dup can't be created in node1"),
{error, conflict} = bo_test_client:signup(Client1, <<"dup">>),

ct:comment("User ok can't be created in node2"),
ct:comment("User dup can't be created in node2"),
{error, conflict} = bo_test_client:signup(Client2, <<"dup">>),

ok
Expand All @@ -96,3 +96,20 @@ duplicated_username(_Config) ->
end,

{comment, ""}.

-spec wrong_username(config()) -> {comment, string()}.
wrong_username(_Config) ->
{ok, Client1} = bo_test_client:start(duplicated_username1),
{ok, Client2} = bo_test_client:start(duplicated_username2),

try
ct:comment("User with invalid name can't be created"),
{error, invalid} = bo_test_client:signup(Client1, not_a_binary),

ok
after
ok = bo_test_client:stop(Client1),
ok = bo_test_client:stop(Client2)
end,

{comment, ""}.
2 changes: 1 addition & 1 deletion test/bo_test_client.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
-export([gen_call/2]).

-type task() :: bo_task:task().
-type player_name() :: binary().
-type player_name() :: term().

-spec start(atom()) -> {ok, node()}.
start(NodeName) ->
Expand Down