From 938ba72570cf51d0f1fd21261d32820cbf3b58c0 Mon Sep 17 00:00:00 2001 From: "halil.cakal" Date: Wed, 18 Jun 2025 14:39:38 +0100 Subject: [PATCH] Ensure teardown.sh is alwasy executed - Currently, on_exit() is advised to run by only 'EXIT' signal that is for gracefull termination - Thus, on_exit() function might not run in cases where job terminates abruptly - To guarantee on_exit() alwasy being called, then add other common termination signals: SIGINT, SIGTERM, and SIGQUIT - This will allow the trap command to catch these signals and execute on_exit() before it terminates. Definition of the signals: - SIGINT: Interrupt signal - SIGTERM: Termination signal, a generic signal used to request a process to terminate. - SIGQUIT: Quit signal Issue-ID: CPS-2821 Change-Id: I96e5d3d42fb26d5dbad75df63a23419914c44fa5 Signed-off-by: halil.cakal --- k6-tests/run-k6-tests.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/k6-tests/run-k6-tests.sh b/k6-tests/run-k6-tests.sh index 74021ec28b..6c2416b9d8 100755 --- a/k6-tests/run-k6-tests.sh +++ b/k6-tests/run-k6-tests.sh @@ -1,6 +1,6 @@ #!/bin/bash # -# Copyright 2024 Nordix Foundation. +# Copyright 2024-2025 OpenInfra Foundation Europe. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,6 +23,8 @@ set -o pipefail # Use last non-zero exit code in a pipeline # Default test profile is kpi. testProfile=${1:-kpi} +# Cleanup handler: capture exit status, run teardown, +# and restore directory, report failures, and exit with original code. on_exit() { rc=$? ./teardown.sh "$testProfile" @@ -30,7 +32,9 @@ on_exit() { echo "TEST FAILURES: $rc" exit $rc } -trap on_exit EXIT + +# Call on_exit, on script exit (EXIT) or when interrupted (SIGINT, SIGTERM, SIGQUIT) to perform cleanup +trap on_exit EXIT SIGINT SIGTERM SIGQUIT pushd "$(dirname "$0")" || exit 1 -- 2.16.6