chore: run nightly tests in parallel

This commit is contained in:
Patryk Osmaczko 2024-02-29 08:59:26 +01:00 committed by osmaczko
parent a63d33e04a
commit abfaa3cf8d
3 changed files with 51 additions and 22 deletions

2
.gitignore vendored
View File

@ -85,6 +85,8 @@ report.xml
# go test logs # go test logs
test.log test.log
test_*.log
**/exit_code_*.txt
# Waku libs # Waku libs
vendor/github.com/waku-org/go-zerokit-rln-x86_64/ vendor/github.com/waku-org/go-zerokit-rln-x86_64/

View File

@ -314,6 +314,7 @@ docker-test: ##@tests Run tests in a docker container with golang.
test: test-unit ##@tests Run basic, short tests during development test: test-unit ##@tests Run basic, short tests during development
test-unit: export BUILD_TAGS ?= test-unit: export BUILD_TAGS ?=
test-unit: export UNIT_TEST_COUNT ?= 1
test-unit: export UNIT_TEST_FAILFAST ?= true test-unit: export UNIT_TEST_FAILFAST ?= true
test-unit: export UNIT_TEST_RERUN_FAILS ?= true test-unit: export UNIT_TEST_RERUN_FAILS ?= true
test-unit: export UNIT_TEST_USE_DEVELOPMENT_LOGGER ?= true test-unit: export UNIT_TEST_USE_DEVELOPMENT_LOGGER ?= true
@ -325,7 +326,14 @@ test-unit: export UNIT_TEST_PACKAGES ?= $(shell go list ./... | \
grep -v /t/benchmarks | \ grep -v /t/benchmarks | \
grep -v /transactions/fake | \ grep -v /transactions/fake | \
grep -E -v '/wakuv2(/.*|$$)') grep -E -v '/wakuv2(/.*|$$)')
test-unit: export UNIT_TEST_PACKAGES_WITH_EXTENDED_TIMEOUT ?= github.com/status-im/status-go/protocol test-unit: export UNIT_TEST_PACKAGES_NOT_PARALLELIZABLE ?= \
github.com/status-im/status-go/api \
github.com/status-im/status-go/mailserver \
github.com/status-im/status-go/multiaccounts/settings \
github.com/status-im/status-go/node \
github.com/status-im/status-go/services/wakuext
test-unit: export UNIT_TEST_PACKAGES_WITH_EXTENDED_TIMEOUT ?= \
github.com/status-im/status-go/protocol
test-unit: ##@tests Run unit and integration tests test-unit: ##@tests Run unit and integration tests
./_assets/scripts/run_unit_tests.sh ./_assets/scripts/run_unit_tests.sh

View File

@ -46,6 +46,16 @@ has_extended_timeout() {
return 1 return 1
} }
is_parallelizable() {
local package
for package in ${UNIT_TEST_PACKAGES_NOT_PARALLELIZABLE}; do
if [[ "$1" == "${package}" ]]; then
return 1
fi
done
return 0
}
run_test_for_package() { run_test_for_package() {
local package=$1 local package=$1
local iteration=$2 local iteration=$2
@ -61,6 +71,7 @@ run_test_for_package() {
local report_file="${package_dir}/report_${iteration}.xml" local report_file="${package_dir}/report_${iteration}.xml"
local rerun_report_file="${package_dir}/report_rerun_fails_${iteration}.txt" local rerun_report_file="${package_dir}/report_rerun_fails_${iteration}.txt"
local exit_code_file="${package_dir}/exit_code_${iteration}.txt"
gotestsum_flags="${GOTESTSUM_EXTRAFLAGS}" gotestsum_flags="${GOTESTSUM_EXTRAFLAGS}"
if [[ "${CI}" == 'true' ]]; then if [[ "${CI}" == 'true' ]]; then
@ -73,35 +84,43 @@ run_test_for_package() {
-count 1 \ -count 1 \
-tags "${BUILD_TAGS}" | \ -tags "${BUILD_TAGS}" | \
redirect_stdout "${output_file}" redirect_stdout "${output_file}"
return $?
}
last_failing_exit_code=0 local go_test_exit=$?
echo "${go_test_exit}" > "${exit_code_file}"
if [[ "${go_test_exit}" -ne 0 ]]; then
if [[ "${CI}" == 'true' ]]; then
echo -e "${YLW}Failed, see the log:${RST} ${BLD}${output_file}${RST}"
fi
fi
return ${go_test_exit}
}
for package in ${UNIT_TEST_PACKAGES}; do for package in ${UNIT_TEST_PACKAGES}; do
for ((i=1; i<=UNIT_TEST_COUNT; i++)); do for ((i=1; i<=UNIT_TEST_COUNT; i++)); do
run_test_for_package "${package}" "${i}" if ! is_parallelizable "${package}" || [[ "$UNIT_TEST_FAILFAST" == 'true' ]]; then
go_test_exit=$? run_test_for_package "${package}" "${i}"
if [[ "${go_test_exit}" -ne 0 ]]; then
if [[ "${CI}" == 'true' ]]; then
echo -e "${YLW}Failed, see the log:${RST} ${BLD}${output_file}${RST}"
fi
if [[ "$UNIT_TEST_FAILFAST" == 'true' ]]; then if [[ "$UNIT_TEST_FAILFAST" == 'true' ]]; then
exit "${go_test_exit}" go_test_exit=$?
if [[ "${go_test_exit}" -ne 0 ]]; then
exit "${go_test_exit}"
fi
fi fi
else
last_failing_exit_code="${go_test_exit}" run_test_for_package "${package}" "${i}" &
fi fi
done done
wait # Wait for all background jobs to finish
done done
if [[ "${last_failing_exit_code}" -ne 0 ]]; then shopt -s globstar nullglob # Enable recursive globbing
if [[ "${UNIT_TEST_COUNT}" -gt 1 ]]; then if [[ "${UNIT_TEST_COUNT}" -gt 1 ]]; then
mkdir -p "${GIT_ROOT}/reports" for exit_code_file in "${GIT_ROOT}"/**/exit_code_*.txt; do
"${GIT_ROOT}/_assets/scripts/test_stats.py" | redirect_stdout "${GIT_ROOT}/reports/test_stats.txt" read exit_code < "${exit_code_file}"
fi if [[ "${exit_code}" -ne 0 ]]; then
mkdir -p "${GIT_ROOT}/reports"
exit "${last_failing_exit_code}" "${GIT_ROOT}/_assets/scripts/test_stats.py" | redirect_stdout "${GIT_ROOT}/reports/test_stats.txt"
exit ${exit_code}
fi
done
fi fi