Skip to content

Commit

Permalink
Merge pull request #4403 from esl/rerun-failed-tests
Browse files Browse the repository at this point in the history
Enable 'rerun failed tests' for big tests in CircleCI
  • Loading branch information
arcusfelis authored Dec 2, 2024
2 parents 96818b2 + 6c1acd8 commit 2bde4e7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tools/select_suites_to_run.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
%% Escript used to filter the test spec according to a list of allowed suites
%% This is used to rerun failed tests on CircleCI
%%
%% Arguments: TEST_SPEC SUITE1 SUITE2 ..
%% Example arguments: default.spec muc_SUITE rdbms_SUITE

-module(select_suites_to_run).
-export([main/1]).

main([SpecFile | SuiteStrings]) ->
Suites = [list_to_atom(Str) || Str <- SuiteStrings],
io:format("Allowed suites: ~p~n", [Suites]),
{ok, OldTerms} = file:consult(SpecFile),
NewTerms = lists:filter(fun(Term) -> filter_term(Term, Suites) end, OldTerms),
write_terms(SpecFile, NewTerms),
ok.

filter_term(Term, Suites) when element(1, Term) == suites;
element(1, Term) == groups;
element(1, Term) == cases ->
lists:member(element(3, Term), Suites);
filter_term(_Term, _Suites) ->
true.

write_terms(Filename, List) ->
Format = fun(Term) -> io_lib:format("~tp.~n", [Term]) end,
Text = lists:map(Format, List),
file:write_file(Filename, Text).
9 changes: 9 additions & 0 deletions tools/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ run_test_preset() {
cd ${BASE}/big_tests
local MAKE_RESULT=0
TESTSPEC=${TESTSPEC:-default.spec}
maybe_select_suites
if [ "$COVER_ENABLED" = "true" ]; then
make cover_test_preset TESTSPEC=$TESTSPEC PRESET=$PRESET CT_HOOKS=$CT_HOOKS
MAKE_RESULT=$?
Expand All @@ -157,6 +158,14 @@ run_test_preset() {
return ${MAKE_RESULT}
}

maybe_select_suites() {
if command -v circleci; then
circleci tests glob tests/*_SUITE.erl | \
circleci tests run --command=">selected_suites xargs -d' ' -I {} basename {} .erl"
escript ../tools/select_suites_to_run.erl $TESTSPEC $(<selected_suites)
fi
}

print_running_nodes() {
echo "Running nodes:"
# Expand wildcard into a bash array
Expand Down

0 comments on commit 2bde4e7

Please sign in to comment.