Skip to content

Commit c7b4ce5

Browse files
committed
ci: add flaky test re-execution on Windows
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 6d8a34a commit c7b4ce5

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
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) {

0 commit comments

Comments
 (0)