Skip to content

Commit e774b44

Browse files
authored
fix(e2e): Add cleanup trap to prevent false positives in CI test runs (istio-ecosystem#1227)
* fix(e2e): Add cleanup trap to prevent false positives in CI test runs The e2e test script was storing the Ginkgo exit code but could still exit unexpectedly before cleanup, causing CI to mark incomplete test runs as successful (false positives). Signed-off-by: Francisco Herrera <[email protected]> * TEMPORARY FAILURE TEMPORARY FAILURE: check failure test on CI Signed-off-by: Francisco Herrera <[email protected]> * Fix lint Fix lint messages Signed-off-by: Francisco Herrera <[email protected]> * Revert "TEMPORARY FAILURE" This reverts commit 5346be9. Signed-off-by: Francisco Herrera <[email protected]> --------- Signed-off-by: Francisco Herrera <[email protected]>
1 parent 749d908 commit e774b44

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

tests/e2e/common-operator-integ-suite.sh

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,32 @@ await_operator() {
146146
"${COMMAND}" wait --for=condition=available deployment/"${DEPLOYMENT_NAME}" -n "${NAMESPACE}" --timeout=5m
147147
}
148148

149+
# shellcheck disable=SC2329 # Function is invoked indirectly via trap
149150
uninstall_operator() {
150151
echo "Uninstalling sail-operator (KUBECONFIG=${KUBECONFIG})"
151152
helm uninstall sail-operator --namespace "${NAMESPACE}"
152153
"${COMMAND}" delete namespace "${NAMESPACE}"
153154
}
154155

156+
# Ensure cleanup always runs and that the original test exit code is preserved
157+
# shellcheck disable=SC2329 # Function is invoked indirectly via trap
158+
cleanup() {
159+
# Do not let cleanup errors affect the final exit code
160+
set +e
161+
if [ "${OLM}" != "true" ] && [ "${SKIP_DEPLOY}" != "true" ]; then
162+
if [ "${MULTICLUSTER}" == true ]; then
163+
KUBECONFIG="${KUBECONFIG}" uninstall_operator || true
164+
# shellcheck disable=SC2153 # KUBECONFIG2 is set by multicluster setup scripts
165+
KUBECONFIG="${KUBECONFIG2}" uninstall_operator || true
166+
else
167+
uninstall_operator || true
168+
fi
169+
fi
170+
echo "JUnit report: ${ARTIFACTS}/report.xml"
171+
}
172+
173+
trap cleanup EXIT INT TERM
174+
155175
# Main script flow
156176
check_arguments "$@"
157177
parse_flags "$@"
@@ -231,24 +251,12 @@ if [ "${OLM}" != "true" ] && [ "${SKIP_DEPLOY}" != "true" ]; then
231251
fi
232252

233253
set +e
234-
# Disable to avoid fail the test run and not generate the report.xml
235-
# We need to catch the exit code to be able to generate the report
254+
# Disable to avoid failing the test run before generating the report.xml
255+
# Capture the test exit code and allow cleanup via trap to run
236256
# shellcheck disable=SC2086
237257
IMAGE="${HUB}/${IMAGE_BASE}:${TAG}" \
238258
go run github.com/onsi/ginkgo/v2/ginkgo -tags e2e \
239259
--timeout 60m --junit-report="${ARTIFACTS}/report.xml" ${GINKGO_FLAGS:-} "${WD}"/...
240260
TEST_EXIT_CODE=$?
241-
set -e
242-
243-
if [ "${OLM}" != "true" ] && [ "${SKIP_DEPLOY}" != "true" ]; then
244-
if [ "${MULTICLUSTER}" == true ]; then
245-
KUBECONFIG="${KUBECONFIG}" uninstall_operator
246-
KUBECONFIG="${KUBECONFIG2}" uninstall_operator
247-
else
248-
uninstall_operator
249-
fi
250-
fi
251-
252261

253-
echo "JUnit report: ${ARTIFACTS}/report.xml"
254-
exit ${TEST_EXIT_CODE}
262+
exit "${TEST_EXIT_CODE}"

0 commit comments

Comments
 (0)