Files
ajp_anton 1c713ff635
Build custom container images / build (map[base_image:php:8-fpm-alpine build_args:PHP_VERSION=8 context:php8-pgsql fingerprint_command:{ apk info -v | LC_ALL=C sort; find /usr/local/lib/php/extensions /usr/local/etc/php/conf.d -type f -exec sha256sum {} + | LC_ALL=C sort; } name:ph… (push) Successful in 50s
Build custom container images / build (map[base_image:postgres:18 build_args:PG_VERSION=18 POSTGIS_VERSION=3 VCHORD_VERSION=0.5.3 context:postgres fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; find /usr/lib/postgresql -type f -exec sha256su… (push) Successful in 50s
Build custom container images / build (map[base_image:python:3 build_args:PYTHON_VERSION=3 context:python-tools fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; } name:python-tools oci_labels:org.opencontainers.ima… (push) Successful in 1m37s
Build custom container images / build (map[base_image:python:3.12-slim build_args:PYTHON_VERSION=3.12-slim context:linkki-tiedotus fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; } name:linkki-tiedotus oci_labels:… (push) Successful in 36s
Build custom container images / build (map[base_image:python:3.12-slim build_args:PYTHON_VERSION=3.12-slim context:timepoll fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; } name:timepoll oci_labels:org.opencontai… (push) Successful in 42s
Simplify task input handling and tighten runner coordination
2026-11-01 16:44:11 +00:00

124 lines
4.8 KiB
Python

import json
import os
import time
import threading
from concurrent.futures import ThreadPoolExecutor
from datetime import UTC, datetime, timedelta
from app.web import create_app
from .conftest import write_task
from .test_runner import wait_for
def test_concurrent_cleanup_passes_do_not_overlap(manager, monkeypatch):
entered = threading.Event()
release = threading.Event()
calls = []
def cleanup(*args):
calls.append(args)
if len(calls) == 1:
entered.set()
assert release.wait(5)
monkeypatch.setattr(manager, '_cleanup_transient_files', cleanup)
with ThreadPoolExecutor() as pool:
first = pool.submit(manager.cleanup_transient_files)
assert entered.wait(5)
second = pool.submit(manager.cleanup_transient_files)
try:
time.sleep(.1)
assert len(calls) == 1
finally:
release.set()
first.result(timeout=5)
second.result(timeout=5)
assert len(calls) == 2
def test_active_inputs_and_artifacts_never_expire(manager, monkeypatch):
run, _ = manager.store.enqueue(target_kind="task", target_path="example/task.py", queue_group="example")
manager.store.claim_next("example")
root = manager.settings.state_root / "runs"
for name in (f"{run.id}.artifacts", f"{run.id}.uploads"):
path = root / name
path.mkdir(parents=True)
(path / "data").write_text("active")
os.utime(path, (time.time() - 3 * 86400,) * 2)
input_path = root / f"{run.id}.input.json"
input_path.write_text("{}")
monkeypatch.setattr(manager.store, "run_lifetimes", lambda: {})
manager.cleanup_transient_files()
assert input_path.exists()
assert (root / f"{run.id}.artifacts/data").exists()
assert (root / f"{run.id}.uploads/data").exists()
def test_artifact_retention_starts_at_completion_not_directory_creation(manager):
run, _ = manager.store.enqueue(target_kind="task", target_path="example/task.py", queue_group="example")
manager.store.finish(run.id, status="succeeded")
root = manager.settings.state_root / "runs"
artifact = root / f"{run.id}.artifacts"
artifact.mkdir(parents=True)
(artifact / "report.json").write_text("{}")
os.utime(artifact, (time.time() - 3 * 86400,) * 2)
(root / f"{run.id}.input.json").write_text("{}")
manager.cleanup_transient_files()
assert (artifact / "report.json").exists()
assert not (root / f"{run.id}.input.json").exists()
old = (datetime.now(UTC) - timedelta(days=3)).isoformat()
with manager.store._connect() as connection:
connection.execute("UPDATE runs SET finished_at = ? WHERE id = ?", (old, run.id))
manager.cleanup_transient_files()
assert not artifact.exists()
def test_failed_task_keeps_valid_diagnostics_but_not_incomplete_downloads(manager):
write_task(manager.settings.task_root, "example", "fail.py", '''
import os
from pathlib import Path
root = Path(os.environ["SERVER_MAINTENANCE_ARTIFACTS"])
(root / "report.json").write_text('{"completed_steps": 2}')
(root / "broken.json").write_text('{')
(root / "partial.zip").write_bytes(b"partial")
raise SystemExit(1)
''')
task = manager.catalog.task("example/fail.py")
run, _ = manager.run_task(task)
wait_for(manager, run.id, {"failed"})
assert manager.artifacts(run.id) == ["report.json"]
assert not (manager.settings.state_root / "runs" / f"{run.id}.input.json").exists()
def test_failed_json_report_is_accessible(settings):
app = create_app(settings)
manager = app.extensions["run_manager"]
run, _ = manager.store.enqueue(target_kind="task", target_path="example/fail.py", queue_group="example")
manager.store.finish(run.id, status="failed")
root = settings.state_root / "runs" / f"{run.id}.artifacts"
root.mkdir(parents=True)
(root / "report.json").write_text('{"completed_steps":2}')
client = app.test_client()
response = client.get(f"/runs/{run.id}/artifacts/report.json/view")
assert response.status_code == 200
assert json.loads(response.data) == {"completed_steps": 2}
def test_aborted_artifact_download_can_be_retried(settings):
app = create_app(settings)
manager = app.extensions["run_manager"]
run, _ = manager.store.enqueue(target_kind="task", target_path="example/archive.py", queue_group="example")
manager.store.finish(run.id, status="succeeded")
root = settings.state_root / "runs" / f"{run.id}.artifacts"
root.mkdir(parents=True)
path = root / "review.zip"
path.write_bytes(b"x" * 100_000)
client = app.test_client()
response = client.get(f"/runs/{run.id}/artifacts/review.zip", buffered=False)
next(iter(response.response))
response.close()
assert path.exists()
retry = client.get(f"/runs/{run.id}/artifacts/review.zip")
assert len(retry.data) == 100_000
assert not path.exists()