Skip to content
Snippets Groups Projects
Unverified Commit 92cdde89 authored by Alessio Caiazza's avatar Alessio Caiazza Committed by Tomasz Maczukin
Browse files

Merge branch 'fix-test-failure-detection' into 'master'

Fix test failure detection

See merge request gitlab-org/gitlab-runner!993
parent f664ee03
Branches
Tags
No related merge requests found
...@@ -37,8 +37,7 @@ prepareTestCommands() { ...@@ -37,8 +37,7 @@ prepareTestCommands() {
local testIndex=0 local testIndex=0
local runTests=() local runTests=()
local tests local tests=$(go test -list "Test.*" "${pkg}" | grep "^Test" || echo "")
tests=$(go test -list "Test.*" "${pkg}" | grep "^Test" || echo "")
if [[ -z "${tests}" ]]; then if [[ -z "${tests}" ]]; then
continue continue
...@@ -76,8 +75,7 @@ executeTestCommand() { ...@@ -76,8 +75,7 @@ executeTestCommand() {
local options="" local options=""
local pkgSlug local pkgSlug=$(echo "${pkg}" | tr "/" "-")
pkgSlug=$(echo "${pkg}" | tr "/" "-")
if [[ ${TESTFLAGS} = *"-cover"* ]]; then if [[ ${TESTFLAGS} = *"-cover"* ]]; then
mkdir -p ".cover" mkdir -p ".cover"
...@@ -85,28 +83,28 @@ executeTestCommand() { ...@@ -85,28 +83,28 @@ executeTestCommand() {
printMessage "\\n\\n--- Starting part ${index} of go tests of '${pkg}' package with coverprofile in '${coverMode}' mode:\\n" printMessage "\\n\\n--- Starting part ${index} of go tests of '${pkg}' package with coverprofile in '${coverMode}' mode:\\n"
profileFile=".cover/${pkgSlug}.${index}.${coverMode}.cover.txt" local profileFile=".cover/${pkgSlug}.${index}.${coverMode}.cover.txt"
options="-covermode=${coverMode} -coverprofile=${profileFile}" options="-covermode=${coverMode} -coverprofile=${profileFile}"
else else
echo "Starting go test" echo "Starting go test"
fi fi
testOutputFile=".testoutput/${pkgSlug}.${index}.${output}.output.txt" local testOutputFile=".testoutput/${pkgSlug}.${index}.${output}.output.txt"
exitCode=0 local exitCode=0
# shellcheck disable=SC2086 # shellcheck disable=SC2086
go test ${options} ${TESTFLAGS} -v "${pkg}" -run "${runTestsList}" 2>&1 | tee "${testOutputFile}" || exitCode=1 go test ${options} ${TESTFLAGS} -v "${pkg}" -run "${runTestsList}" 2>&1 | tee "${testOutputFile}" || exitCode=1
return $exitCode return ${exitCode}
} }
executeTestPart() { executeTestPart() {
rm -rf ".cover/" rm -rf ".cover/"
rm -rf ".testoutput/" rm -rf ".testoutput/"
numberOfDefinitions=$(< "${testsDefinitions}" wc -l) local numberOfDefinitions=$(< "${testsDefinitions}" wc -l)
executionSize=$((numberOfDefinitions/SUITE_TOTAL+1)) local executionSize=$((numberOfDefinitions/SUITE_TOTAL+1))
executionOffset=$((SUITE_INDEX*executionSize+1)) local executionOffset=$((SUITE_INDEX*executionSize+1))
printMessage "Number of definitions: ${numberOfDefinitions}" printMessage "Number of definitions: ${numberOfDefinitions}"
printMessage "Suite size: ${SUITE_TOTAL}" printMessage "Suite size: ${SUITE_TOTAL}"
...@@ -115,12 +113,12 @@ executeTestPart() { ...@@ -115,12 +113,12 @@ executeTestPart() {
printMessage "Execution size: ${executionSize}" printMessage "Execution size: ${executionSize}"
printMessage "Execution offset: ${executionOffset}" printMessage "Execution offset: ${executionOffset}"
exitCode=0 local exitCode=0
while read -r pkg index tests; do while read -r pkg index tests; do
executeTestCommand "${pkg}" "${index}" "${tests}" || exitCode=1 executeTestCommand "${pkg}" "${index}" "${tests}" || exitCode=1
done < <(tail -n +${executionOffset} ${testsDefinitions} | head -n ${executionSize}) done < <(tail -n +${executionOffset} ${testsDefinitions} | head -n ${executionSize})
exit $exitCode exit ${exitCode}
} }
computeCoverageReport() { computeCoverageReport() {
...@@ -140,7 +138,7 @@ computeCoverageReport() { ...@@ -140,7 +138,7 @@ computeCoverageReport() {
go tool cover -o ${textReportFile} -func=${sourceFile} go tool cover -o ${textReportFile} -func=${sourceFile}
printMessage "General coverage percentage:" printMessage "General coverage percentage:"
total=$(grep "total" "${textReportFile}" || echo "") local total=$(grep "total" "${textReportFile}" || echo "")
if [[ -n "${total}" ]]; then if [[ -n "${total}" ]]; then
echo "${output} ${total}" echo "${output} ${total}"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment