Files
computer-playbook/scripts/tests/deploy/utils/rescue/window.sh
T
kevinveenbirkenbachandClaude Opus 5.5 8a0e858f12 refactor(ci): group the rescue helpers under scripts/tests/deploy/utils/rescue
2bf329cd3b put rescue_window.sh next to rescue_index.sh, and
test_prefix_grouped_files rejects two siblings sharing the `rescue`
prefix (quality-high pass 67). Both move to utils/rescue/ as index.sh and
window.sh, their tests to the mirrored tests/.../utils/rescue/, and every
caller follows: dedicated.sh, the swarm teardown in 00_one.sh, the
workspace workflow, and the swarm and diagnostics READMEs.

The budget-kill drill gave the stand-in a 1 s budget; under the full
parallel unit run the SIGTERM arrived before its EXIT trap was installed,
so nothing was captured and the test failed. The two kill drills now use
KILL_BUDGET = 3 s; their assertions are unchanged. A full `make test-unit`
passes them under load.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 20:01:54 +01:00

25 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Time window of one rescue-trap step, carved out of the distro budget's kill grace.
#
# Reads:
# INFINITO_CI_DISTRO_DEADLINE_EPOCH epoch distros.sh sends the budget SIGTERM at
# INFINITO_CI_DISTRO_KILL_EPOCH epoch distros.sh sends the SIGKILL at; unset outside distros.sh
#
# Sets in the caller:
# rescue_secs timeout of the step
# rescue_until epoch the step must end by; empty while the step keeps its nominal time
# Param: $1 seconds the step takes when the trap was not entered by the budget SIGTERM
rescue_window() {
local now
now="$(date +%s)"
rescue_secs="$1"
rescue_until=""
[ -n "${INFINITO_CI_DISTRO_KILL_EPOCH:-}" ] || return 0 # nocheck: distros.sh exports this epoch at run time; a static default would be a stale timestamp
((now >= INFINITO_CI_DISTRO_DEADLINE_EPOCH)) || return 0
rescue_secs="$(((INFINITO_CI_DISTRO_KILL_EPOCH - now + 1) / 2))"
((rescue_secs > 0)) || rescue_secs=1
rescue_until="$((now + rescue_secs))"
echo ">>> Budget kill: $((INFINITO_CI_DISTRO_KILL_EPOCH - now))s left until the SIGKILL, ${rescue_secs}s for this rescue step (until epoch ${rescue_until})"
}