Protect task diagnostics and stream incremental run output
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 38s
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 47s
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 1m24s
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 38s
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 43s
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 38s
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 47s
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 1m24s
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 38s
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 43s
This commit is contained in:
1 parent
0aa67439fd
commit
55bbbe2fd7
8 files changed
+319
-51
No files matched your search
@@ -0,0 +1,87 @@
|
||||
import pytest
|
||||
|
||||
from app.web import create_app
|
||||
from .conftest import write_task
|
||||
from .test_runner import wait_for, wait_for_output
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def output_run(settings):
|
||||
app = create_app(settings)
|
||||
store = app.extensions["run_store"]
|
||||
run, _ = store.enqueue(target_kind="task", target_path="example/task.py", queue_group="example")
|
||||
store.claim_next("example")
|
||||
path = settings.state_root / "test.log"
|
||||
path.write_bytes(b"first\n")
|
||||
with store._connect() as connection:
|
||||
connection.execute("UPDATE runs SET log_path = ? WHERE id = ?", (str(path), run.id))
|
||||
return app.test_client(), run.id, path, store
|
||||
|
||||
|
||||
def test_log_polling_returns_only_appended_bytes_and_status(output_run):
|
||||
client, run_id, path, store = output_run
|
||||
first = client.get(f"/runs/{run_id}/output?offset=0").get_json()
|
||||
assert first == {"output": "first\n", "offset": 6, "reset": False, "has_more": False, "status": "running"}
|
||||
with path.open("ab") as stream:
|
||||
stream.write("next: \u20ac\n".encode())
|
||||
store.finish(run_id, status="succeeded")
|
||||
next_chunk = client.get(f"/runs/{run_id}/output?offset=6").get_json()
|
||||
assert next_chunk["output"] == "next: \u20ac\n"
|
||||
assert next_chunk["offset"] == path.stat().st_size
|
||||
assert next_chunk["status"] == "succeeded"
|
||||
assert client.get(f"/runs/{run_id}/output").get_json() == {"output": "first\nnext: \u20ac\n"}
|
||||
|
||||
|
||||
def test_incomplete_utf8_is_deferred_until_the_next_poll(output_run):
|
||||
client, run_id, path, _ = output_run
|
||||
path.write_bytes(b"ok\xe2\x82")
|
||||
first = client.get(f"/runs/{run_id}/output?offset=0").get_json()
|
||||
assert first["output"] == "ok"
|
||||
assert first["offset"] == 2
|
||||
with path.open("ab") as stream:
|
||||
stream.write(b"\xac")
|
||||
second = client.get(f"/runs/{run_id}/output?offset=2").get_json()
|
||||
assert second["output"] == "\u20ac"
|
||||
assert second["offset"] == 5
|
||||
|
||||
|
||||
def test_truncated_log_resets_the_browser_offset(output_run):
|
||||
client, run_id, path, _ = output_run
|
||||
path.write_bytes(b"new")
|
||||
result = client.get(f"/runs/{run_id}/output?offset=6").get_json()
|
||||
assert result["reset"] is True
|
||||
assert result["output"] == "new"
|
||||
assert result["offset"] == 3
|
||||
|
||||
|
||||
def test_large_log_is_drained_in_bounded_chunks(output_run):
|
||||
client, run_id, path, store = output_run
|
||||
path.write_bytes(b"x" * (1024 * 1024 - 1) + "\u20ac".encode())
|
||||
store.finish(run_id, status="succeeded")
|
||||
first = client.get(f"/runs/{run_id}/output?offset=0").get_json()
|
||||
assert first["has_more"] is True
|
||||
assert first["offset"] == 1024 * 1024 - 1
|
||||
second = client.get(f"/runs/{run_id}/output?offset={first['offset']}").get_json()
|
||||
assert second["output"] == "\u20ac"
|
||||
assert second["has_more"] is False
|
||||
|
||||
|
||||
@pytest.mark.parametrize("offset", ["-1", "abc", "1.5", "9" * 100, str(2**63)])
|
||||
def test_invalid_log_offset_is_rejected(output_run, offset):
|
||||
client, run_id, _, _ = output_run
|
||||
assert client.get(f"/runs/{run_id}/output?offset={offset}").status_code == 400
|
||||
|
||||
|
||||
def test_running_task_output_is_visible_before_completion(settings):
|
||||
write_task(settings.task_root, "example", "long.py", 'import time\nprint("working", flush=True)\ntime.sleep(30)\n')
|
||||
app = create_app(settings)
|
||||
manager = app.extensions["run_manager"]
|
||||
run, _ = manager.run_task(app.extensions["catalog"].task("example/long.py"))
|
||||
try:
|
||||
wait_for_output(settings.state_root / "runs" / f"{run.id}.log", "working")
|
||||
response = app.test_client().get(f"/runs/{run.id}/output?offset=0").get_json()
|
||||
assert response["status"] == "running"
|
||||
assert response["output"] == "working\n"
|
||||
finally:
|
||||
manager.request_cancel(run.id)
|
||||
wait_for(manager, run.id, {"cancelled"})
|
||||
Reference in new issue
Block a user