Files
moby/hack/test/unit
Paweł Gronowski af82d154e8 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)
2025-05-08 07:59:57 -07:00

76 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Run unit tests and create report
#
# TESTFLAGS - add additional test flags. Ex:
#
# TESTFLAGS='-v -run TestBuild' hack/test/unit
#
# TESTDIRS - run tests for specified packages. Ex:
#
# TESTDIRS='./pkg/term' hack/test/unit
#
set -eux -o pipefail
BUILDFLAGS=(-tags 'netgo libdm_no_deferred_remove')
TESTFLAGS+=" -test.timeout=${TIMEOUT:-5m}"
TESTDIRS="${TESTDIRS:-./...}"
exclude_paths='/vendor/|/integration'
pkg_list=$(go list $TESTDIRS | grep -vE "($exclude_paths)")
base_pkg_list=$(echo "${pkg_list}" | grep --fixed-strings -v "/libnetwork" || :)
libnetwork_pkg_list=$(echo "${pkg_list}" | grep --fixed-strings "/libnetwork" || :)
echo "${libnetwork_pkg_list}" | grep --fixed-strings "libnetwork/drivers/bridge" \
&& if ! type docker-proxy; then
hack/make.sh binary-proxy install-proxy
fi
mkdir -p bundles
if [ -n "${base_pkg_list}" ]; then
gotestsum --format=standard-quiet --jsonfile=bundles/go-test-report.json --junitfile=bundles/junit-report.xml -- \
"${BUILDFLAGS[@]}" \
-cover \
-coverprofile=bundles/coverage.out \
-covermode=atomic \
${TESTFLAGS} \
${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[@]}" \
-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