Skip to content

Commit a064920

Browse files
authored
Merge pull request libgit2#5140 from libgit2/ethomson/flaky_ci
Re-run flaky tests
2 parents a080037 + c7b4ce5 commit a064920

File tree

2 files changed

+60
-9
lines changed

2 files changed

+60
-9
lines changed

ci/test.ps1

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,32 @@ function run_test {
2929
$TestCommand = (ctest -N -V -R "^$TestName$") -join "`n" -replace "(?ms).*\n^[0-9]*: Test command: ","" -replace "\n.*",""
3030
$TestCommand += " -r${BuildDir}\results_${TestName}.xml"
3131

32-
Invoke-Expression $TestCommand
33-
if ($LastExitCode -ne 0) { $global:Success = $false }
32+
if ($Env:GITTEST_FLAKY_RETRY -gt 0) {
33+
$AttemptsRemain = $Env:GITTEST_FLAKY_RETRY
34+
} else {
35+
$AttemptsRemain = 1
36+
}
37+
38+
$Failed = 0
39+
while ($AttemptsRemain -ne 0) {
40+
if ($Failed -eq 1) {
41+
Write-Host ""
42+
Write-Host "Re-running flaky $TestName tests..."
43+
Write-Host ""
44+
}
45+
46+
Invoke-Expression $TestCommand
47+
if ($LastExitCode -eq 0) {
48+
$Failed = 0
49+
break
50+
} else {
51+
$Failed = 1
52+
}
53+
54+
$AttemptsRemain = $AttemptsRemain - 1
55+
}
56+
57+
if ($Failed -eq 1) { $global:Success = $false }
3458
}
3559

3660
Write-Host "##############################################################################"
@@ -79,7 +103,9 @@ if (-not $Env:SKIP_ONLINE_TESTS) {
79103
Write-Host "## Running (online) tests"
80104
Write-Host "##############################################################################"
81105

106+
$Env:GITTEST_FLAKY_RETRY=5
82107
run_test online
108+
$Env:GITTEST_FLAKY_RETRY=0
83109
}
84110

85111
if (-not $Env:SKIP_PROXY_TESTS) {

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)