Ensure teardown.sh is alwasy executed 35/141335/2
authorhalil.cakal <halil.cakal@est.tech>
Wed, 18 Jun 2025 13:39:38 +0000 (14:39 +0100)
committerhalil.cakal <halil.cakal@est.tech>
Thu, 19 Jun 2025 09:25:14 +0000 (10:25 +0100)
- 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 <halil.cakal@est.tech>
k6-tests/run-k6-tests.sh

index 74021ec..6c2416b 100755 (executable)
@@ -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