Skip to content

Commit 1c3de3d

Browse files
author
Tomasz Wojcikowski
committed
Enable rerun failed tests for small and big tests
1 parent 1bb6b68 commit 1c3de3d

File tree

3 files changed

+66
-6
lines changed

3 files changed

+66
-6
lines changed

.circleci/template.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,18 @@ commands:
331331
name: Run Small Tests
332332
command: |
333333
tools/test.sh -p small_tests -s true -e true
334+
- run:
335+
when: always
336+
name: Copy small test results for Insights
337+
command: |
338+
LATEST_CT_RUN=$(ls -td _build/test/logs/ct_run.* 2>/dev/null | head -1)
339+
if [ -n "$LATEST_CT_RUN" ] && [ -f "$LATEST_CT_RUN/junit_report.xml" ]; then
340+
mkdir -p small_tests_test_results
341+
cp "$LATEST_CT_RUN/junit_report.xml" small_tests_test_results/junit_report.xml
342+
fi
343+
- store_test_results:
344+
when: always
345+
path: small_tests_test_results
334346
run_docker_smoke_test:
335347
steps:
336348
- checkout
@@ -637,10 +649,15 @@ jobs:
637649
when: always
638650
name: Copy test results for Insights
639651
command: |
640-
cp big_tests/ct_report/*/junit_report.xml .
652+
LATEST_BIG_CT_RUN=$(ls -td big_tests/ct_report/ct_run.* 2>/dev/null | head -1)
653+
if [ -n "$LATEST_BIG_CT_RUN" ] && [ -f "$LATEST_BIG_CT_RUN/junit_report.xml" ]; then
654+
cp "$LATEST_BIG_CT_RUN/junit_report.xml" big_tests_junit_report.xml
655+
else
656+
echo "No big test junit_report.xml found"
657+
fi
641658
- store_test_results:
642659
when: always
643-
path: junit_report.xml
660+
path: big_tests_junit_report.xml
644661
- run_coverage_analysis
645662
- run:
646663
name: Build Failed - Logs

rebar.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
{overlay, [{template, "rel/files/mongooseim.toml", "etc/mongooseim.toml"}]}]},
181181
{deps, [{proper, "1.5.0"}, {meck, "1.0.0"}, {wait_helper, "0.2.1"}]}]},
182182
{test, [{extra_src_dirs, [{"test", [{recursive, true}]}]},
183+
{ct_opts, [{ct_hooks, [cth_surefire]}]},
183184
{deps, [{proper, "1.5.0"}, {meck, "1.0.0"}, {wait_helper, "0.2.1"}]}]}
184185
]}.
185186

tools/test.sh

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,51 @@ choose_newest_directory() {
7878
fi
7979
}
8080

81+
circleci_tests_available() {
82+
command -v circleci >/dev/null 2>&1 && [[ "$CIRCLECI" == "true" ]]
83+
}
84+
85+
select_circleci_suites() {
86+
local glob_pattern="$1"
87+
local output_file="$2"
88+
89+
rm -f "$output_file"
90+
# Use xargs to normalize input to newlines, then sed to process
91+
# This follows CircleCI docs recommendation to use xargs for input handling
92+
if ! circleci tests glob "$glob_pattern" | \
93+
circleci tests run --command="xargs -n1 echo | sed 's|.*/||; s|\.erl$||' >>$output_file" --verbose
94+
then
95+
echo "circleci tests run failed for pattern $glob_pattern"
96+
return 1
97+
fi
98+
99+
if [ ! -s "$output_file" ]; then
100+
echo "circleci tests run returned no suites for pattern $glob_pattern"
101+
return 1
102+
fi
103+
}
104+
105+
maybe_select_small_test_suites() {
106+
if circleci_tests_available && select_circleci_suites "test/**/*_SUITE.erl" selected_small_suites; then
107+
if [ -s selected_small_suites ]; then
108+
# Convert newline-separated suites to comma-separated list for rebar3
109+
SELECTED_SUITES=$(cat selected_small_suites | tr '\n' ',' | sed 's/,$//')
110+
echo "Selected small test suites: $SELECTED_SUITES"
111+
export SUITE="$SELECTED_SUITES"
112+
fi
113+
else
114+
echo "CircleCI did not return specific small-test suites to rerun; executing default list"
115+
fi
116+
}
117+
81118
run_small_tests() {
82119
tools/print-dots.sh start
83120
tools/print-dots.sh monitor $$
84121
if [ "$COVER_ENABLED" = true ]; then
85122
REBAR_CT_EXTRA_ARGS=" -c $REBAR_CT_EXTRA_ARGS "
86123
fi
87124
export REBAR_CT_EXTRA_ARGS="$REBAR_CT_EXTRA_ARGS"
125+
maybe_select_small_test_suites
88126
make ct
89127
RESULT="$?"
90128
tools/print-dots.sh stop
@@ -159,11 +197,15 @@ run_test_preset() {
159197
}
160198

161199
maybe_select_suites() {
162-
if command -v circleci >/dev/null 2>&1 && [[ "$CIRCLECI" == "true" ]]; then
163-
circleci tests glob tests/*_SUITE.erl | \
164-
circleci tests run --command=">selected_suites xargs -d' ' -I {} basename {} .erl"
165-
escript ../tools/select_suites_to_run.erl $TESTSPEC $(<selected_suites)
200+
if circleci_tests_available && select_circleci_suites "tests/*_SUITE.erl" selected_suites; then
201+
if [ -s selected_suites ]; then
202+
escript ../tools/select_suites_to_run.erl $TESTSPEC $(<selected_suites)
203+
else
204+
echo "CircleCI returned an empty suite list for big tests; running defaults"
166205
fi
206+
else
207+
echo "CircleCI did not provide failed big-test suites; running defaults"
208+
fi
167209
}
168210

169211
print_running_nodes() {

0 commit comments

Comments
 (0)