Commit fb161916 authored by Alessio Caiazza's avatar Alessio Caiazza

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

Fix test failure detection

See merge request gitlab-org/gitlab-runner!993
parents b2bc7b9c 6e3aff15
Pipeline #27665289 failed with stages
in 4 minutes and 22 seconds
......@@ -37,8 +37,7 @@ prepareTestCommands() {
local testIndex=0
local runTests=()
local tests
tests=$(go test -list "Test.*" "${pkg}" | grep "^Test" || echo "")
local tests=$(go test -list "Test.*" "${pkg}" | grep "^Test" || echo "")
if [[ -z "${tests}" ]]; then
continue
......@@ -76,8 +75,7 @@ executeTestCommand() {
local options=""
local pkgSlug
pkgSlug=$(echo "${pkg}" | tr "/" "-")
local pkgSlug=$(echo "${pkg}" | tr "/" "-")
if [[ ${TESTFLAGS} = *"-cover"* ]]; then
mkdir -p ".cover"
......@@ -85,28 +83,28 @@ executeTestCommand() {
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}"
else
echo "Starting go test"
fi
testOutputFile=".testoutput/${pkgSlug}.${index}.${output}.output.txt"
local testOutputFile=".testoutput/${pkgSlug}.${index}.${output}.output.txt"
exitCode=0
local exitCode=0
# shellcheck disable=SC2086
go test ${options} ${TESTFLAGS} -v "${pkg}" -run "${runTestsList}" 2>&1 | tee "${testOutputFile}" || exitCode=1
return $exitCode
return ${exitCode}
}
executeTestPart() {
rm -rf ".cover/"
rm -rf ".testoutput/"
numberOfDefinitions=$(< "${testsDefinitions}" wc -l)
executionSize=$((numberOfDefinitions/SUITE_TOTAL+1))
executionOffset=$((SUITE_INDEX*executionSize+1))
local numberOfDefinitions=$(< "${testsDefinitions}" wc -l)
local executionSize=$((numberOfDefinitions/SUITE_TOTAL+1))
local executionOffset=$((SUITE_INDEX*executionSize+1))
printMessage "Number of definitions: ${numberOfDefinitions}"
printMessage "Suite size: ${SUITE_TOTAL}"
......@@ -115,12 +113,12 @@ executeTestPart() {
printMessage "Execution size: ${executionSize}"
printMessage "Execution offset: ${executionOffset}"
exitCode=0
local exitCode=0
while read -r pkg index tests; do
executeTestCommand "${pkg}" "${index}" "${tests}" || exitCode=1
done < <(tail -n +${executionOffset} ${testsDefinitions} | head -n ${executionSize})
exit $exitCode
exit ${exitCode}
}
computeCoverageReport() {
......@@ -140,7 +138,7 @@ computeCoverageReport() {
go tool cover -o ${textReportFile} -func=${sourceFile}
printMessage "General coverage percentage:"
total=$(grep "total" "${textReportFile}" || echo "")
local total=$(grep "total" "${textReportFile}" || echo "")
if [[ -n "${total}" ]]; then
echo "${output} ${total}"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment