ci(molecule): stop a scenario that runs past its own time limit
A hung scenario held its lane until the job's 90-minute timeout, and the cancel then lost every scenario's log, since the groups print only after the final wait. Each molecule test now runs under coreutils timeout with MOLECULE_SCENARIO_TIMEOUT seconds (default 1800), so the hang fails by itself, its log says it timed out, and the other lanes finish. timeout runs with --foreground so it and molecule stay in the script's process group: without it timeout leads a group of its own, which a cancel that kills the step's group no longer reaches (the killed-group test fails). On expiry molecule alone is signalled; anything it leaves ends with the run container (docker run --init). Closes #474 Assisted-by: Claude Code
This commit is contained in:
1 parent
e8f739904a
commit
41820fd9a7
3 files changed
+60
-7
No files matched your search
@@ -2,7 +2,8 @@
|
||||
# The Molecule workflow's "Run the scenarios" step: `molecule test` for each scenario directory on
|
||||
# stdin, MOLECULE_LANES (default 2, also when empty) at a time, longest first, each with its own
|
||||
# log and ANSIBLE_HOME under <work-dir>/<n>/ (no collection is installed there:
|
||||
# .config/molecule/config.yml sets prerun false).
|
||||
# .config/molecule/config.yml sets prerun false). A scenario still running after
|
||||
# MOLECULE_SCENARIO_TIMEOUT seconds (default 1800, also when empty) is stopped and fails.
|
||||
# Exit 1 on a failure.
|
||||
#
|
||||
# scripts/run_molecule_scenarios.sh <work-dir> < scenario-dirs
|
||||
@@ -14,6 +15,13 @@ if ! [[ "$lanes" =~ ^[1-9][0-9]*$ ]]; then
|
||||
echo "MOLECULE_LANES must be a positive integer, not '$lanes'" >&2
|
||||
exit 2
|
||||
fi
|
||||
# 1800: the longest scenario takes about 8.5 min, and two hung ones plus the rest still end inside
|
||||
# the job's 90 min, so a hang fails on its own with its log printed.
|
||||
limit="${MOLECULE_SCENARIO_TIMEOUT:-1800}"
|
||||
if ! [[ "$limit" =~ ^[1-9][0-9]*$ ]]; then
|
||||
echo "MOLECULE_SCENARIO_TIMEOUT must be a positive integer, not '$limit'" >&2
|
||||
exit 2
|
||||
fi
|
||||
if [ "$#" -ne 1 ]; then
|
||||
echo "usage: $0 <work-dir> < scenario-dirs" >&2
|
||||
exit 2
|
||||
@@ -62,8 +70,14 @@ run_one() {
|
||||
export ANSIBLE_HOME="$out/ansible"
|
||||
# a role scenario runs from its role's directory, as molecule expects
|
||||
case "$dir" in roles/*) cd "${dir%/molecule/*}" || exit 1 ;; esac
|
||||
molecule test -s "${dir##*/}"
|
||||
# --foreground keeps timeout and molecule in this script's process group, so a cancel that
|
||||
# kills the group still reaches them; on expiry it signals molecule alone, not its children.
|
||||
timeout --foreground --kill-after=30 "$limit" molecule test -s "${dir##*/}"
|
||||
) >"$out/log" 2>&1 </dev/null || rc=$?
|
||||
# 124 after TERM, 137 when the KILL of --kill-after was needed
|
||||
if { [ "$rc" -eq 124 ] || [ "$rc" -eq 137 ]; } && [ "$((SECONDS - start))" -ge "$limit" ]; then
|
||||
echo "timed out after $limit s" >>"$out/log"
|
||||
fi
|
||||
if ! remove_instances "$dir" >>"$out/log" 2>&1; then
|
||||
echo "could not remove the containers of $dir" >>"$out/log"
|
||||
if [ "$rc" -eq 0 ]; then rc=1; fi
|
||||
|
||||
Reference in new issue
Block a user