-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#14] Get tests to run on player node
- Loading branch information
Brujo Benavides
committed
Jul 3, 2016
1 parent
ad2d29e
commit 1ba7ba2
Showing
9 changed files
with
158 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
-module(bo_remoteness_SUITE). | ||
-author('elbrujohalcon@inaka.net'). | ||
|
||
-export([all/0]). | ||
-export([init_per_suite/1, end_per_suite/1]). | ||
-export([run/1, crash/1]). | ||
|
||
-type config() :: proplists:proplist(). | ||
|
||
-spec all() -> [atom()]. | ||
all() -> [run, crash]. | ||
|
||
-spec init_per_suite(config()) -> config(). | ||
init_per_suite(Config) -> | ||
case net_kernel:start(['bo_test@127.0.0.1']) of | ||
{ok, _} -> ok; | ||
{error, {already_started, _}} -> ok; | ||
{error, Error} -> throw(Error) | ||
end, | ||
_ = application:load(beam_olympics), | ||
application:set_env(beam_olympics, all_tasks, [bo_test_node_task]), | ||
{ok, _} = bo:start(), | ||
_ = sumo:delete_all(bo_players), | ||
{ok, Client} = bo_test_client:start(bo_remoteness), | ||
[{client, Client} | Config]. | ||
|
||
-spec end_per_suite(config()) -> config(). | ||
end_per_suite(Config) -> | ||
{client, Client} = lists:keyfind(client, 1, Config), | ||
ok = bo_test_client:stop(Client), | ||
_ = sumo:delete_all(bo_players), | ||
application:unset_env(beam_olympics, all_tasks), | ||
ok = bo:stop(), | ||
Config. | ||
|
||
-spec run(config()) -> {comment, string()}. | ||
run(Config) -> | ||
{client, Client} = lists:keyfind(client, 1, Config), | ||
{ok, #{name := bo_test_node_task}} = | ||
bo_test_client:signup(Client, <<"remoteness">>), | ||
|
||
ct:comment("This node is not correct"), | ||
Node = node(), | ||
WrongFun = fun() -> Node end, | ||
{failures, [_|_]} = bo_test_client:submit(Client, <<"remoteness">>, WrongFun), | ||
|
||
ct:comment("Computing the node works, because test is run on client node"), | ||
RightFun = fun() -> node() end, | ||
the_end = bo_test_client:submit(Client, <<"remoteness">>, RightFun), | ||
|
||
{comment, ""}. | ||
|
||
-spec crash(config()) -> {comment, string()}. | ||
crash(Config) -> | ||
{client, Client} = lists:keyfind(client, 1, Config), | ||
{ok, #{name := bo_test_node_task}} = | ||
bo_test_client:signup(Client, <<"crash">>), | ||
|
||
ct:comment("Crashing crashes only the client node"), | ||
CrashFun = | ||
fun() -> erlang:apply(erlang, halt, ["Crashed by Remoteness Test"]) end, | ||
try bo_test_client:submit(Client, <<"crash">>, CrashFun) of | ||
R -> ct:fail("Unexpected result ~p", [R]) | ||
catch | ||
_:{timeout, Client, _} -> ok | ||
end, | ||
|
||
{comment, ""}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
-module(bo_test_node_task). | ||
|
||
-behaviour(bo_task). | ||
|
||
-export([ description/0 | ||
, spec/0 | ||
, score/0 | ||
, timeout/0 | ||
, tests/0 | ||
]). | ||
|
||
-spec description() -> binary(). | ||
description() -> <<"Return the node you are on regardless of input">>. | ||
|
||
-spec spec() -> bo_task:spec(). | ||
spec() -> #{input => [], output => <<"node()">>}. | ||
|
||
-spec score() -> 100. | ||
score() -> 100. | ||
|
||
-spec timeout() -> 1000. | ||
timeout() -> 1000. | ||
|
||
-spec tests() -> [bo_task:test()]. | ||
tests() -> [build_test()]. | ||
|
||
build_test() -> | ||
fun(Fun) -> | ||
Output = Fun(), | ||
case node() of | ||
Output -> ok; | ||
Expected -> {error, #{ output => Output | ||
, expected => Expected | ||
}} | ||
end | ||
end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters