fix: address pipeline-reliability verify findings

Close the source image after converting to RGBA so PNGs at the pixel limit
fit the render memory limit. Strengthen the fencing test so that it fails
without the attempt check, and measure worker and relay stops under load.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-31 18:55:38 +03:00
co-authored by Claude Opus 5.5
parent 6bd60532aa
commit 399da054f2
19 changed files with 596 additions and 41 deletions
+112 -8
View File
@@ -1761,17 +1761,18 @@ def wait_extra_record(
event: str,
*,
timeout: float = 30,
extra: str = "worker",
**fields: Any,
) -> dict[str, Any]:
deadline = time.monotonic() + timeout
while True:
for record in extra_records(stand):
for record in extra_records(stand, extra):
if record.get("event") == event and all(
record.get(name) == value for name, value in fields.items()
):
return record
assert time.monotonic() < deadline, (
f"no extra worker record {event!r} with {fields} in {timeout} s"
f"no {extra} record {event!r} with {fields} in {timeout} s"
)
time.sleep(0.3)
@@ -5260,18 +5261,121 @@ def test_render_killed(
assert done["attempt"] == 2, done
@pytest.mark.spec("attachment-processing", "Зависший worker")
@pytest.mark.spec("attachment-processing", "Прежняя попытка при живой новой")
def test_hung_worker_lease_fencing(
api: Api,
stand: Stand,
alice: Actor,
chat: dict[str, Any],
) -> None:
"""Первый worker — со сроками больше времени теста: разморозка застаёт его
таймеры живыми, и он доходит до фиксации, где решает только номер попытки (с
обычными сроками его прервал бы таймер, а не fencing). Аренду делает истекшей
hook, а не ожидание: при таком сроке попытки её не дождаться. Второй процесс —
основной worker стенда."""
"""Первая попытка размораживается, когда вторая жива: задание в `processing`,
блокировки строки нет. Решает только номер попытки: по `state` фиксация первой
прошла бы. Оба worker — со сроками больше времени теста, иначе при разморозке
их прервал бы таймер, а не fencing. S3 заморожен, пока вторая не взята: она
ждёт его и не успеет зафиксировать результат раньше своей заморозки. Итог даёт
только вторая. Аренду делает истекшей hook: при таком сроке её не дождаться."""
second = "worker-second"
timers = (
"WORKER__JOB_TIMEOUT_SECONDS=120",
"WORKER__RENDER_TIMEOUT_SECONDS=60",
"S3__TIMEOUT_SECONDS=60",
)
seen_relay = len(relay_records(stand))
try:
with worker_stopped(stand):
accepted = api.upload(alice, chat["id"], images.sample_png())
attachment_id = accepted["id"]
wait_queue_messages(stand, 1)
with outage(stand, "pause", "s3"):
stand("run-worker", *timers)
wait_job(stand, attachment_id, state="processing", attempt=1)
wait_extra_record(
stand,
"Started job attempt",
attachment_id=attachment_id,
attempt=1,
)
stand("pause-extra", "worker")
stand("expire-lease", attachment_id)
wait_relay_record(
stand,
"Recovered expired lease",
skip=seen_relay,
attachment_id=attachment_id,
)
stand("run-worker-second", *timers)
wait_job(stand, attachment_id, state="processing", attempt=2)
wait_extra_record(
stand,
"Started job attempt",
extra=second,
attachment_id=attachment_id,
attempt=2,
)
stand("pause-extra", second)
# вторая взята и заморожена в вызове S3: транзакции нет
assert stand("attachment-free", attachment_id)
taken = job_row(stand, attachment_id)
assert taken is not None
assert taken["state"] == "processing", taken
assert taken["attempt"] == 2, taken
stand("unpause-extra", "worker")
wait_extra_record(
stand,
"Skipped job message",
attachment_id=attachment_id,
attempt=1,
reason="superseded",
)
assert job_row(stand, attachment_id) == taken
assert (
assert_ok(
api.attachment_meta(alice, attachment_id),
200,
"Attachment",
)["status"]
== "processing"
)
stand("unpause-extra", second)
meta = api.wait_attachment(
alice,
attachment_id,
timeout=JOB_WAIT_S,
)
wait_extra_record(
stand,
"Attachment became ready",
extra=second,
attachment_id=attachment_id,
attempt=2,
)
job = job_row(stand, attachment_id)
assert job is not None
assert job["state"] == "succeeded", job
assert job["attempt"] == 2, job
assert not [
record
for record in extra_records(stand)
if record.get("event") == "Attachment became ready"
and record.get("attachment_id") == attachment_id
]
finally:
stand("stop-extra")
assert_variants(api, stand, alice, meta)
@pytest.mark.spec("attachment-processing", "Зависший worker")
def test_hung_worker_thawed_after_ready(
api: Api,
stand: Stand,
alice: Actor,
chat: dict[str, Any],
) -> None:
"""Вторая попытка уже дала `ready`, первая разморожена: итог её не меняет.
Первый worker — со сроками больше времени теста: разморозка застаёт его
таймеры живыми, и он доходит до фиксации (с обычными сроками его прервал бы
таймер, а не fencing). Здесь решает и `state`; номер попытки —
`test_hung_worker_lease_fencing`. Второй процесс — основной worker стенда."""
seen_relay = len(relay_records(stand))
with worker_stopped(stand):
accepted = api.upload(alice, chat["id"], images.sample_png())