Preserve active staging and read published originals on reprocessing
This commit is contained in:
@@ -4,12 +4,17 @@ from uuid import UUID, uuid4
|
||||
|
||||
import pytest
|
||||
from httpx import AsyncClient
|
||||
from test_attachments import storage
|
||||
from test_pipeline import accepted, job_of, rows
|
||||
|
||||
from conftest import DATABASE, actor
|
||||
from messenger.admin import serve
|
||||
from messenger.attachments.application.commands import ReprocessAttachment
|
||||
from messenger.attachments.application.pipeline import AFTER_S3_WRITE, ReprocessAttachmentHandler
|
||||
from messenger.attachments.application.pipeline import (
|
||||
AFTER_CLAIM,
|
||||
AFTER_S3_WRITE,
|
||||
ReprocessAttachmentHandler,
|
||||
)
|
||||
from messenger.attachments.application.ports import Rendition
|
||||
from messenger.attachments.domain.errors import ImageTooDemanding
|
||||
from messenger.attachments.domain.jobs import Outcome, ReprocessResult
|
||||
@@ -80,20 +85,22 @@ async def test_version_order_never_reverts_published_bytes(
|
||||
|
||||
|
||||
class PausedEffect:
|
||||
def __init__(self) -> None:
|
||||
def __init__(self, point: str) -> None:
|
||||
self.point = point
|
||||
self.reached = asyncio.Event()
|
||||
self.resume = asyncio.Event()
|
||||
|
||||
async def reach(self, point: str) -> None:
|
||||
if point == AFTER_S3_WRITE:
|
||||
if point == self.point:
|
||||
self.reached.set()
|
||||
await self.resume.wait()
|
||||
|
||||
|
||||
async def test_old_holder_finishes_after_new_publication(client: AsyncClient) -> None:
|
||||
@pytest.mark.parametrize("point", [AFTER_CLAIM, AFTER_S3_WRITE])
|
||||
async def test_old_holder_finishes_after_new_publication(client: AsyncClient, point: str) -> None:
|
||||
_, bob, ident = await accepted(client)
|
||||
old, new = await pipeline_of(client), await pipeline_of(client)
|
||||
old.faults = pause = PausedEffect()
|
||||
old.faults = pause = PausedEffect(point)
|
||||
job = await job_of(ident)
|
||||
running = asyncio.create_task(old.process(job))
|
||||
try:
|
||||
@@ -102,8 +109,10 @@ async def test_old_holder_finishes_after_new_publication(client: AsyncClient) ->
|
||||
jobs = await versions(new, ident)
|
||||
assert await new.process(jobs[2]) is Outcome.DONE
|
||||
public = (await client.get(f"/api/v1/attachments/{ident}", headers=actor(bob))).json()
|
||||
assert await new.clean() == 0
|
||||
pause.resume.set()
|
||||
assert await asyncio.wait_for(running, 5) is Outcome.SUPERSEDED
|
||||
assert await new.clean() == 1
|
||||
assert (await attachment(ident))["published_version"] == 2
|
||||
assert (
|
||||
await client.get(f"/api/v1/attachments/{ident}", headers=actor(bob))
|
||||
@@ -178,3 +187,14 @@ async def test_operator_cli_schedules_version_once(
|
||||
report = json.loads(capsys.readouterr().out.splitlines()[-1])
|
||||
assert report["result"] == expected
|
||||
assert report["pipeline_version"] == 2
|
||||
|
||||
|
||||
async def test_ready_reprocess_survives_cleanup_before_metadata_commit(client: AsyncClient) -> None:
|
||||
_, _, ident = await accepted(client)
|
||||
pipeline = await pipeline_of(client)
|
||||
await pipeline.drain()
|
||||
await (await storage(client)).delete(f"staging/{ident}")
|
||||
assert await reprocess(pipeline, ident) is ReprocessResult.QUEUED
|
||||
jobs = await versions(pipeline, ident)
|
||||
assert await pipeline.process(jobs[2]) is Outcome.DONE
|
||||
assert (await attachment(ident))["published_version"] == 2
|
||||
|
||||
Reference in New Issue
Block a user