ci(molecule): start the longest scenarios first and pass the lane count in
Part of #432. A long scenario started late sets the end of a full run, so run_molecule_scenarios.sh now starts scenarios by the durations of the last full run, longest first, with an unlisted scenario first; the log groups keep the selection order. A workflow_dispatch input `lanes` reaches the script as MOLECULE_LANES, so full runs with different lane counts can be compared; an empty value keeps the default of 4. The shared molecule config enables ansible.posix.profile_tasks (summary only) and ansible.posix.timer, so each scenario's log shows where its time goes. Assisted-by: Claude Code
This commit is contained in:
1 parent
a2ab13a6e1
commit
ef840c8952
6 files changed
+123
-8
No files matched your search
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# The Molecule workflow's "Run the scenarios" step: `molecule test` for each scenario directory on
|
||||
# stdin, MOLECULE_LANES (default 4) at a time, each with its own log and ANSIBLE_HOME under
|
||||
# stdin, MOLECULE_LANES (default 4, 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).
|
||||
# Exit 1 on a failure.
|
||||
#
|
||||
@@ -77,6 +77,36 @@ while IFS= read -r dir; do
|
||||
done
|
||||
mkdir -p "$work"
|
||||
|
||||
# Seconds each scenario took in the last full run, so the longest start first and none started
|
||||
# late sets the end of the run. Refresh from a full run's `finished <label>: exit 0 after S s`
|
||||
# lines; a scenario missing here is assumed long and starts first.
|
||||
declare -A last_seconds=(
|
||||
[roles/system_baseline/molecule/default]=1127
|
||||
[roles/ufw/molecule/default]=907
|
||||
[roles/traefik/molecule/default]=886
|
||||
[roles/gitea_runner/molecule/default]=762
|
||||
[roles/cloudflared/molecule/default]=673
|
||||
[roles/docker/molecule/default]=612
|
||||
[roles/tailscale/molecule/default]=509
|
||||
[roles/fail2ban/molecule/default]=337
|
||||
[roles/systemd_hardening/molecule/default]=335
|
||||
[roles/gitea/molecule/default]=301
|
||||
[roles/user_management/molecule/default]=270
|
||||
[roles/_binary_update/molecule/default]=248
|
||||
[roles/pihole/molecule/default]=228
|
||||
[roles/sshd/molecule/default]=163
|
||||
[roles/pve_lxc/molecule/default]=157
|
||||
[roles/network_interfaces/molecule/default]=129
|
||||
[roles/_binary_update/molecule/check_mode]=81
|
||||
[extensions/molecule/image-smoke]=47
|
||||
[extensions/molecule/image-smoke-2604]=46
|
||||
)
|
||||
# The indices of dirs in start order; ties keep the selection order (a stable sort).
|
||||
mapfile -t start_order < <(
|
||||
for n in "${!dirs[@]}"; do printf '%s %s\n' "${last_seconds[${dirs[$n]}]:-999999}" "$n"; done |
|
||||
sort -s -k1,1nr | cut -d' ' -f2
|
||||
)
|
||||
|
||||
# A cancelled job must not leave lanes behind that recreate containers after the next run's
|
||||
# cleanup. A signal to this script stops each lane's tree so it cannot fork, then terminates it,
|
||||
# with the whole group of any descendant that leads one: ansible's workers detach into their own.
|
||||
@@ -110,7 +140,7 @@ trap 'stop_lanes 143' TERM
|
||||
trap 'stop_lanes 130' INT
|
||||
trap 'stop_lanes 129' HUP
|
||||
|
||||
for n in "${!dirs[@]}"; do
|
||||
for n in "${start_order[@]}"; do
|
||||
while [ "$(jobs -rp | wc -l)" -ge "$lanes" ]; do wait -n || true; done
|
||||
run_one "$n" "${dirs[$n]}" </dev/null &
|
||||
done
|
||||
|
||||
Reference in new issue
Block a user