Skip to content

Commit c0f0f2a

Browse files
committed
test: add robust signal-aware soak cleanup traps
Register INT, TERM, and EXIT traps with idempotent cleanup so interrupted soak runs reliably remove test resources while preserving real non-zero failures. Made-with: Cursor
1 parent 36837b7 commit c0f0f2a

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

scripts/soak-test.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ THRESHOLD_KB=5120 # 5 MB growth limit
1717
NODE_COUNT=100
1818
TEST_NAMESPACE="${TEST_NAMESPACE:-soak-test}"
1919
RESULTS_FILE="${RESULTS_FILE:-/tmp/soak-memory.log}"
20+
CLEANUP_DONE=false
2021

2122
# ── Helpers ──────────────────────────────────────────────────────────────────
2223

@@ -66,6 +67,46 @@ delete_nodes() {
6667
--timeout=120s 2>/dev/null || true
6768
}
6869

70+
cleanup_resources() {
71+
local reason="${1:-exit}"
72+
if [[ "$CLEANUP_DONE" == "true" ]]; then
73+
echo "[cleanup] Already completed (reason: ${reason})"
74+
return
75+
fi
76+
CLEANUP_DONE=true
77+
78+
echo "[cleanup] Starting cleanup (reason: ${reason})..."
79+
delete_nodes || true
80+
kubectl delete namespace "$TEST_NAMESPACE" --ignore-not-found --wait=false >/dev/null 2>&1 || true
81+
echo "[cleanup] Cleanup finished for namespace: ${TEST_NAMESPACE}"
82+
}
83+
84+
handle_exit() {
85+
local exit_code=$?
86+
cleanup_resources "exit"
87+
if [[ $exit_code -ne 0 ]]; then
88+
echo "[cleanup] Exiting with failure code: ${exit_code}"
89+
else
90+
echo "[cleanup] Exiting successfully"
91+
fi
92+
exit "$exit_code"
93+
}
94+
95+
handle_signal() {
96+
local signal_name="$1"
97+
local signal_code=1
98+
case "$signal_name" in
99+
INT) signal_code=130 ;;
100+
TERM) signal_code=143 ;;
101+
esac
102+
echo "[cleanup] Received ${signal_name}; requesting graceful shutdown..."
103+
exit "$signal_code"
104+
}
105+
106+
trap 'handle_signal INT' INT
107+
trap 'handle_signal TERM' TERM
108+
trap 'handle_exit' EXIT
109+
69110
# ── Setup ─────────────────────────────────────────────────────────────────────
70111

71112
kubectl create namespace "$TEST_NAMESPACE" --dry-run=client -o yaml | kubectl apply -f -

0 commit comments

Comments
 (0)