From 6c1acd8e4fca5f37716587aa3332cc0eebc7bb1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chrz=C4=85szcz?= Date: Fri, 29 Nov 2024 14:34:52 +0100 Subject: [PATCH] Enable 'rerun failed tests' in CircleCI - Call 'circleci tests glob' and 'circleci tests run' as described in https://circleci.com/docs/rerun-failed-tests/#output-test-files-only - Add an escript to filter the selected tests. This is similar to 'selected_tests_to_test_spec.erl', but the filtering is different: - Only suites from the original specs are allowed. This is to avoid running tests from outside of the current spec. - Filtering is only by suite (not by tests or groups) --- tools/select_suites_to_run.erl | 28 ++++++++++++++++++++++++++++ tools/test.sh | 9 +++++++++ 2 files changed, 37 insertions(+) create mode 100644 tools/select_suites_to_run.erl diff --git a/tools/select_suites_to_run.erl b/tools/select_suites_to_run.erl new file mode 100644 index 00000000000..7ae5865a89d --- /dev/null +++ b/tools/select_suites_to_run.erl @@ -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). diff --git a/tools/test.sh b/tools/test.sh index 77a378a237c..1309ca9042c 100755 --- a/tools/test.sh +++ b/tools/test.sh @@ -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=$? @@ -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 $(