hack/unit: Rerun failed flaky libnetwork tests

libnetwork tests tend to be flaky (namely `TestNetworkDBIslands` and
`TestNetworkDBCRUDTableEntries`).

Move execution of tests which name has `TestFlaky` prefix to a separate
gotestsum pass which allows them to be reran 4 times.

On Windows, the libnetwork test execution is not split into a separate
pass.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
(cherry picked from commit d0d8d5d97d)
This commit is contained in:
Paweł Gronowski
2024-03-12 12:08:20 +01:00
committed by Andrey Epifanov
parent 0d4fb6cf12
commit af82d154e8
2 changed files with 42 additions and 3 deletions

View File

@@ -332,10 +332,26 @@ Function Run-UnitTests() {
$pkgList = $pkgList | Select-String -NotMatch "github.com/docker/docker/integration"
$pkgList = $pkgList -replace "`r`n", " "
$jsonFilePath = $bundlesDir + "\go-test-report-unit-flaky-tests.json"
$xmlFilePath = $bundlesDir + "\junit-report-unit-flaky-tests.xml"
$coverageFilePath = $bundlesDir + "\coverage-report-unit-flaky-tests.txt"
$goTestArg = "--rerun-fails=4 --format=standard-verbose --jsonfile=$jsonFilePath --junitfile=$xmlFilePath """ + "--packages=$pkgList" + """ -- " + $raceParm + " -coverprofile=$coverageFilePath -covermode=atomic -ldflags -w -a -test.timeout=10m -test.run=TestFlaky.*"
Write-Host "INFO: Invoking unit tests run with $GOTESTSUM_LOCATION\gotestsum.exe $goTestArg"
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pinfo.FileName = "$GOTESTSUM_LOCATION\gotestsum.exe"
$pinfo.WorkingDirectory = "$($PWD.Path)"
$pinfo.UseShellExecute = $false
$pinfo.Arguments = $goTestArg
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $pinfo
$p.Start() | Out-Null
$p.WaitForExit()
if ($p.ExitCode -ne 0) { Throw "Unit tests (flaky) failed" }
$jsonFilePath = $bundlesDir + "\go-test-report-unit-tests.json"
$xmlFilePath = $bundlesDir + "\junit-report-unit-tests.xml"
$coverageFilePath = $bundlesDir + "\coverage-report-unit-tests.txt"
$goTestArg = "--format=standard-verbose --jsonfile=$jsonFilePath --junitfile=$xmlFilePath -- " + $raceParm + " -coverprofile=$coverageFilePath -covermode=atomic -ldflags -w -a """ + "-test.timeout=10m" + """ $pkgList"
$goTestArg = "--format=standard-verbose --jsonfile=$jsonFilePath --junitfile=$xmlFilePath -- " + $raceParm + " -coverprofile=$coverageFilePath -covermode=atomic -ldflags -w -a -test.timeout=10m -test.skip=TestFlaky.*" + " $pkgList"
Write-Host "INFO: Invoking unit tests run with $GOTESTSUM_LOCATION\gotestsum.exe $goTestArg"
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pinfo.FileName = "$GOTESTSUM_LOCATION\gotestsum.exe"

View File

@@ -38,15 +38,38 @@ if [ -n "${base_pkg_list}" ]; then
${base_pkg_list}
fi
if [ -n "${libnetwork_pkg_list}" ]; then
rerun_flaky=1
gotest_extra_flags="-skip=TestFlaky.*"
# Custom -run passed, don't run flaky tests separately.
if echo "$TESTFLAGS" | grep -Eq '(-run|-test.run)[= ]'; then
rerun_flaky=0
gotest_extra_flags=""
fi
# libnetwork tests invoke iptables, and cannot be run in parallel. Execute
# tests within /libnetwork with '-p=1' to run them sequentially. See
# https://github.com/moby/moby/issues/42458#issuecomment-873216754 for details.
gotestsum --format=standard-quiet --jsonfile=bundles/go-test-report-libnetwork.json --junitfile=bundles/junit-report-libnetwork.xml -- \
"${BUILDFLAGS[@]}" \
gotestsum --format=standard-quiet --jsonfile=bundles/go-test-report-libnetwork.json --junitfile=bundles/junit-report-libnetwork.xml \
-- "${BUILDFLAGS[@]}" \
-cover \
-coverprofile=bundles/coverage-libnetwork.out \
-covermode=atomic \
-p=1 \
${gotest_extra_flags} \
${TESTFLAGS} \
${libnetwork_pkg_list}
if [ $rerun_flaky -eq 1 ]; then
gotestsum --format=standard-quiet --jsonfile=bundles/go-test-report-libnetwork-flaky.json --junitfile=bundles/junit-report-libnetwork-flaky.xml \
--packages "${libnetwork_pkg_list}" \
--rerun-fails=4 \
-- "${BUILDFLAGS[@]}" \
-cover \
-coverprofile=bundles/coverage-libnetwork-flaky.out \
-covermode=atomic \
-p=1 \
-test.run 'TestFlaky.*' \
${TESTFLAGS}
fi
fi