Skip to content

Commit 6d8a34a

Browse files
committed
ci: add flaky test re-execution on Unix
Our online tests are occasionally flaky since they hit real network endpoints. Re-run them up to 5 times if they fail, to allow us to avoid having to fail the whole build.
1 parent a080037 commit 6d8a34a

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

ci/test.sh

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ cleanup() {
3232
echo "Done."
3333
}
3434

35-
failure() {
36-
echo "Test exited with code: $1"
37-
SUCCESS=0
38-
}
39-
4035
# Ask ctest what it would run if we were to invoke it directly. This lets
4136
# us manage the test configuration in a single place (tests/CMakeLists.txt)
4237
# instead of running clar here as well. But it allows us to wrap our test
@@ -60,7 +55,35 @@ run_test() {
6055
RUNNER="$TEST_CMD"
6156
fi
6257

63-
eval $RUNNER || failure
58+
if [[ "$GITTEST_FLAKY_RETRY" > 0 ]]; then
59+
ATTEMPTS_REMAIN=$GITTEST_FLAKY_RETRY
60+
else
61+
ATTEMPTS_REMAIN=1
62+
fi
63+
64+
FAILED=0
65+
while [[ "$ATTEMPTS_REMAIN" > 0 ]]; do
66+
if [ "$FAILED" -eq 1 ]; then
67+
echo ""
68+
echo "Re-running flaky ${1} tests..."
69+
echo ""
70+
fi
71+
72+
RETURN_CODE=0
73+
eval $RUNNER || RETURN_CODE=$? && true
74+
75+
if [ "$RETURN_CODE" -eq 0 ]; then
76+
break
77+
fi
78+
79+
echo "Test exited with code: $RETURN_CODE"
80+
ATTEMPTS_REMAIN="$(($ATTEMPTS_REMAIN-1))"
81+
FAILED=1
82+
done
83+
84+
if [ "$FAILED" -ne 0 ]; then
85+
SUCCESS=0
86+
fi
6487
}
6588

6689
# Configure the test environment; run them early so that we're certain
@@ -166,7 +189,9 @@ if [ -z "$SKIP_ONLINE_TESTS" ]; then
166189
echo "## Running (online) tests"
167190
echo "##############################################################################"
168191

192+
export GITTEST_FLAKY_RETRY=5
169193
run_test online
194+
unset GITTEST_FLAKY_RETRY
170195
fi
171196

172197
if [ -z "$SKIP_GITDAEMON_TESTS" ]; then
@@ -238,7 +263,7 @@ fi
238263

239264
cleanup
240265

241-
if [ "$SUCCESS" -ne "1" ]; then
266+
if [ "$SUCCESS" -ne 1 ]; then
242267
echo "Some tests failed."
243268
exit 1
244269
fi

0 commit comments

Comments
 (0)