Skip to content

Commit b05aeae

Browse files
authored
Merge pull request #4586 from esl/tomasz/MIM-2364-rerun-flaky-tests
[CI] Enable "Rerun Failed Tests" for Small Tests
2 parents da4222f + 30f28e5 commit b05aeae

File tree

5 files changed

+73
-15
lines changed

5 files changed

+73
-15
lines changed

.circleci/template.yml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,8 @@ commands:
326326
steps:
327327
- run:
328328
name: Coverage
329-
when: on_success
329+
when: always
330330
command: |
331-
echo "Success!"
332331
./rebar3 codecov analyze
333332
tools/circle-upload-codecov.sh
334333
run_small_tests:
@@ -342,6 +341,18 @@ commands:
342341
name: Run Small Tests
343342
command: |
344343
tools/test.sh -p small_tests -s true -e true
344+
- run:
345+
when: always
346+
name: Copy small test results for Insights
347+
command: |
348+
LATEST_CT_RUN=$(ls -td _build/test/logs/ct_run.* 2>/dev/null | head -1)
349+
if [ -n "$LATEST_CT_RUN" ] && [ -f "$LATEST_CT_RUN/junit_report.xml" ]; then
350+
mkdir -p small_tests_test_results
351+
cp "$LATEST_CT_RUN/junit_report.xml" small_tests_test_results/junit_report.xml
352+
fi
353+
- store_test_results:
354+
when: always
355+
path: small_tests_test_results
345356
run_docker_smoke_test:
346357
steps:
347358
- checkout
@@ -648,10 +659,16 @@ jobs:
648659
when: always
649660
name: Copy test results for Insights
650661
command: |
651-
cp big_tests/ct_report/*/junit_report.xml .
662+
LATEST_BIG_CT_RUN=$(ls -td big_tests/ct_report/ct_run.* 2>/dev/null | head -1)
663+
if [ -n "$LATEST_BIG_CT_RUN" ] && [ -f "$LATEST_BIG_CT_RUN/junit_report.xml" ]; then
664+
mkdir -p big_tests_test_results
665+
cp "$LATEST_BIG_CT_RUN/junit_report.xml" big_tests_test_results/junit_report.xml
666+
else
667+
echo "No big test junit_report.xml found"
668+
fi
652669
- store_test_results:
653670
when: always
654-
path: junit_report.xml
671+
path: big_tests_test_results
655672
- run_coverage_analysis
656673
- run:
657674
name: Build Failed - Logs

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ clean:
2020
# REBAR_CT_EXTRA_ARGS comes from a test runner
2121
ct:
2222
@(if [ "$(SUITE)" ]; \
23-
then $(RUN) $(REBAR) ct --dir test --suite $(SUITE) ; \
23+
then $(RUN) $(REBAR) ct --dir test --suite $(SUITE) $(REBAR_CT_EXTRA_ARGS); \
2424
else $(RUN) $(REBAR) ct $(REBAR_CT_EXTRA_ARGS); fi)
2525

2626
eunit:

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/circle-publish-github-comment.sh

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,10 @@ function last_ct_run_name
8585
}
8686

8787

88-
function small_suite_path
88+
function last_small_ct_run_name
8989
{
9090
if [ -d _build/test/logs ]; then
91-
cd _build/test/logs
92-
ls -t -1 ct_run.mongooseim@localhost.*/lib.mongooseim.logs/run.*/suite.log.html
93-
cd ../../..
91+
ls -1 -t _build/test/logs/ | grep ct_run | head -n1
9492
fi
9593
}
9694

@@ -106,8 +104,8 @@ function ct_small_url
106104
{
107105
local CT_REPORTS=$(ct_reports_dir)
108106
local SMALL_TESTS_URL="$(archive_reader_url small ${CT_REPORTS})"
109-
local SUFFIX=$(small_suite_path)
110-
echo "$SMALL_TESTS_URL/$SUFFIX"
107+
local RUN_PART=$(echo "$(last_small_ct_run_name)" | sed "s/@/%40/g")
108+
echo "$SMALL_TESTS_URL/$RUN_PART/index.html"
111109
}
112110

113111
function reports_url

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)