Skip to content
Open
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ $ bin/shell
Run a specific test (the shell offers autocompletion):

```sh
([email protected])1> eunit:test(ar_fork_recovery_tests:height_plus_one_fork_recovery_test_()).
bin/test ar_fork_recovery_tests:height_plus_one_fork_recovery_test_
```

If it fails, the nodes keep running so you can inspect them through Erlang shell or HTTP API.
Expand Down
24 changes: 23 additions & 1 deletion apps/arweave/src/ar.erl
Original file line number Diff line number Diff line change
Expand Up @@ -871,9 +871,10 @@ tests(Mods, Config) when is_list(Mods) ->
io:format("Failed to start the peers due to ~p:~p~n", [Type, Reason]),
erlang:halt(1)
end,
Tests = extract_single_test(Mods),
Result =
try
eunit:test({timeout, ?TEST_TIMEOUT, [Mods]}, [verbose, {print_depth, 100}])
eunit:test({timeout, ?TEST_TIMEOUT, [Tests]}, [verbose, {print_depth, 100}])
after
ar_test_node:stop_peers()
end,
Expand All @@ -882,6 +883,27 @@ tests(Mods, Config) when is_list(Mods) ->
_ -> erlang:halt(1)
end.

extract_single_test(Modules) ->
lists:map(
fun(TestRep) ->
case string:split(atom_to_list(TestRep), ":") of
[TestModule, TestFunction] ->
parse_generator_or_test(TestModule, TestFunction);
_ ->
TestRep
end
end,
Modules
).

parse_generator_or_test(TestModule, TestFunction) ->
TestType = case string:split(TestFunction, "_test_") of
[_, []] ->
generator;
_ ->
test
end,
{TestType, list_to_atom(TestModule), list_to_atom(TestFunction)}.

start_for_tests(Config) ->
UniqueName = ar_test_node:get_node_namespace(),
Expand Down
14 changes: 12 additions & 2 deletions bin/test
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,20 @@ cd "$SCRIPT_DIR/.."

export ERL_EPMD_ADDRESS=127.0.0.1

if [[ $# -gt 0 ]]; then
MODULES=$@
else
SRC_MODULES=$(ls $SCRIPT_DIR/../apps/arweave/src | sed -n 's/.erl$//p' | sort)
TEST_MODULE_BASENAMES=$(ls $SCRIPT_DIR/../apps/arweave/test | sed -n 's/_tests.erl$//p' | sort)
NON_SRC_TEST_MODULE_BASENAMES=$(comm -13 <(printf "%s\n" $SRC_MODULES) <(printf "%s\n" $TEST_MODULE_BASENAMES))
NON_SRC_TEST_MODULES=$(echo $NON_SRC_TEST_MODULE_BASENAMES | xargs -I{} echo '{}_tests')
MODULES="$SRC_MODULES $NON_SRC_TEST_MODULES"
fi

ERL_TEST_OPTS="-pa `./rebar3 as test path` `./rebar3 as test path --base`/lib/arweave/test -config config/sys.config"
echo -e "\033[0;32m===> Running tests...\033[0m"

set -x
set -o pipefail
stdbuf -oL -eL erl $ERL_TEST_OPTS -noshell -name [email protected] -setcookie test -run ar tests ${@:1} -s init stop 2>&1 | tee main-localtest.out
set +x
stdbuf -oL -eL erl $ERL_TEST_OPTS -noshell -name [email protected] -setcookie test -run ar tests $MODULES -s init stop 2>&1 | tee main-localtest.out
set +x