Skip to content

Commit

Permalink
chore: run nightly tests one by one
Browse files Browse the repository at this point in the history
fixes: #4585
fixes: #4586
  • Loading branch information
osmaczko committed Feb 28, 2024
1 parent 577db51 commit a068b64
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 28 deletions.
12 changes: 6 additions & 6 deletions _assets/ci/Jenkinsfile.tests
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,19 @@ pipeline {
script { env.PKG_URL = "${currentBuild.absoluteUrl}/consoleText" }
script {
if (isTestNightlyJob()) {
archiveArtifacts artifacts: '**/report.xml, **/test.log'
archiveArtifacts artifacts: '**/report_*.xml, **/test_*.log'

def totalSize = sh(script: "find . -name 'report.xml' | xargs wc -c | tail -n1 | awk '{print \$1}'", returnStdout: true).trim()
echo "Total size of all report.xml files: ${totalSize} bytes"
def totalSize = sh(script: "find . -name 'report_*.xml' | xargs wc -c | tail -n1 | awk '{print \$1}'", returnStdout: true).trim()
echo "Total size of all report_*.xml files: ${totalSize} bytes"
}
if (params.UNIT_TEST_RERUN_FAILS) {
def rerunReports = findFiles(glob: '**/report_rerun_fails.txt')
def rerunReports = findFiles(glob: '**/report_rerun_fails_*.txt')
if (rerunReports.length > 0) {
archiveArtifacts artifacts: '**/report_rerun_fails.txt'
archiveArtifacts artifacts: '**/report_rerun_fails_*.txt'
}
}
}
junit testResults: '**/report.xml',
junit testResults: '**/report_*.xml',
skipOldReports: true,
skipPublishingChecks: true,
skipMarkingBuildUnstable: true
Expand Down
53 changes: 32 additions & 21 deletions _assets/scripts/run_unit_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ if [[ -z "${UNIT_TEST_COUNT}" ]]; then
UNIT_TEST_COUNT=1
fi

UNIT_TEST_PACKAGE_TIMEOUT="$((UNIT_TEST_COUNT * 2))m"
UNIT_TEST_PACKAGE_TIMEOUT_EXTENDED="$((UNIT_TEST_COUNT * 30))m"
UNIT_TEST_PACKAGE_TIMEOUT="2m"
UNIT_TEST_PACKAGE_TIMEOUT_EXTENDED="30m"

redirect_stdout() {
output_file=$1

if [[ "${CI}" == 'true' ]];
then
if [[ "${CI}" == 'true' ]]; then
cat > "${output_file}";
else
tee "${output_file}";
Expand All @@ -47,43 +46,55 @@ has_extended_timeout() {
return 1
}

last_failing_exit_code=0

for package in ${UNIT_TEST_PACKAGES}; do
echo -e "${GRN}Testing:${RST} ${package} Count:${UNIT_TEST_COUNT}"
run_test_for_package() {
local package=$1
local iteration=$2
echo -e "${GRN}Testing:${RST} ${package} Iteration:${iteration}"
package_dir=$(go list -f "{{.Dir}}" "${package}")
output_file=${package_dir}/test.log
output_file="${package_dir}/test_${iteration}.log"

if has_extended_timeout "${package}"; then
package_timeout="${UNIT_TEST_PACKAGE_TIMEOUT_EXTENDED}"
else
package_timeout="${UNIT_TEST_PACKAGE_TIMEOUT}"
fi

local report_file="${package_dir}/report_${iteration}.xml"
local rerun_report_file="${package_dir}/report_rerun_fails_${iteration}.txt"

gotestsum_flags="${GOTESTSUM_EXTRAFLAGS}"
if [[ "${CI}" == 'true' ]]; then
gotestsum_flags="${gotestsum_flags} --junitfile=${package_dir}/report.xml --rerun-fails-report=${package_dir}/report_rerun_fails.txt"
gotestsum_flags="${gotestsum_flags} --junitfile=${report_file} --rerun-fails-report=${rerun_report_file}"
fi

gotestsum --packages="${package}" ${gotestsum_flags} -- \
-v ${GOTEST_EXTRAFLAGS} \
-timeout "${package_timeout}" \
-count "${UNIT_TEST_COUNT}" \
-count 1 \
-tags "${BUILD_TAGS}" | \
redirect_stdout "${output_file}"
go_test_exit=$?
return $?
}

if [[ "${go_test_exit}" -ne 0 ]]; then
if [[ "${CI}" == 'true' ]]; then
echo -e "${YLW}Failed, see the log:${RST} ${BLD}${output_file}${RST}"
fi
last_failing_exit_code=0

if [[ "$UNIT_TEST_FAILFAST" == 'true' ]]; then
exit "${go_test_exit}"
fi
for package in ${UNIT_TEST_PACKAGES}; do
for ((i=1; i<=UNIT_TEST_COUNT; i++)); do
run_test_for_package "${package}" "${i}"
go_test_exit=$?

last_failing_exit_code="${go_test_exit}"
fi
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
exit "${go_test_exit}"
fi

last_failing_exit_code="${go_test_exit}"
fi
done
done

if [[ "${last_failing_exit_code}" -ne 0 ]]; then
Expand Down
2 changes: 1 addition & 1 deletion _assets/scripts/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

test_stats = defaultdict(lambda: defaultdict(int))

for file in glob.glob("**/report.xml", recursive=True):
for file in glob.glob("**/report_*.xml", recursive=True):
tree = ET.parse(file)
root = tree.getroot()
for testcase in root.iter("testcase"):
Expand Down

0 comments on commit a068b64

Please sign in to comment.