ci(molecule): hold the sweep bound to the job timeout and tolerate races

A script test now fails when the sweep step's age bound differs from the
job's timeout-minutes, since a shorter bound would remove a live run's
containers. The final cleanup removes this run's containers one by one
and fails only when one is still there, as another run's sweep may have
removed it first once this run passed its timeout.

Assisted-by: Claude Code:claude-opus-5-5
This commit is contained in:
Defame1297 committed 2026-11-24 09:50:34 +00:00
1 parent 6c2e05c95a
commit 4f0b8e0cfe
2 files changed
+27 -8

No files matched your search

+16 -2
View File
@@ -360,10 +360,14 @@ def alive(pid):
def label_filters(step_name):
"""The label filters of a workflow step's docker commands, as `--filter label=<key>[=<value>]`."""
return re.findall(r"--filter ['\"]?label=([^'\"\s]+)", step_run(step_name))
def step_run(step_name):
"""The run: block of the Molecule workflow's step named step_name."""
workflow = yaml.safe_load(WORKFLOW.read_text())
steps = [s for job in workflow["jobs"].values() for s in job.get("steps", [])]
run = next(s["run"] for s in steps if s.get("name") == step_name)
return re.findall(r"--filter ['\"]?label=([^'\"\s]+)", run)
return next(s["run"] for s in steps if s.get("name") == step_name)
class ScenarioPlatformsTest(unittest.TestCase):
@@ -401,6 +405,16 @@ class ScenarioPlatformsTest(unittest.TestCase):
[f"{RUN_LABEL}=$KAMINO_RUN_ID"],
)
def test_the_sweep_spares_containers_younger_than_the_job_timeout(self):
# a shorter bound would remove the containers of a run still going
timeout = yaml.safe_load(WORKFLOW.read_text())["jobs"]["molecule"][
"timeout-minutes"
]
run = step_run("Remove the containers earlier runs left")
self.assertEqual(
re.findall(r"date -d '(\d+) minutes ago'", run), [str(timeout)]
)
if __name__ == "__main__":
unittest.main()