forked from mtusi2026/mtusi2026lab4
End a failed reconciler pass with the dependency error
The merge loop runs inside the TaskGroup that holds the --deep checks, so a listing or page failure in the middle of a pass left the group as an ExceptionGroup. The entry point catches Unavailable only: the pass still exited with code 1, but through an uncaught traceback instead of the reconcile.failed record. The pass now unwraps the group and raises the Unavailable with its original cause; the API test fails the listing on the second page of a deep apply pass and expects Unavailable. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V1d3RLHNBBMA6UqBLLJv27
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
8cd30488d2
commit
3b3cb5bd7f
@@ -17,6 +17,7 @@
|
||||
- [x] 3.2 Платформа: поток журнала настраивается
|
||||
- [x] 3.3 CLI `messenger.attachments.entrypoints.reconcile`: флаги, сборка адаптеров, JSON в stdout, коды выхода
|
||||
- [x] 3.4 Проверка группы: API-тесты сверки против одноразового PostgreSQL (каждый класс в dry-run без изменений, apply и повтор = 0, свежее и используемое сохранены, строка появилась после листинга, карантин и `404`, `healed`, `--deep`, занятая блокировка); тест адаптера против RustFS (порядок листинга, страницы, `HEAD`)
|
||||
- [x] 3.5 Отказ зависимости посреди прохода завершает его исключением `Unavailable`, а не группой исключений `TaskGroup`: журнал `reconcile.failed`, код `1`; API-тест сбоя листинга на второй странице
|
||||
|
||||
## 4. Стенд
|
||||
|
||||
@@ -30,6 +31,8 @@
|
||||
- [x] 5.2 `student-tests/tools/seed_storage.py`: наполнение N объектов и строк в образе API
|
||||
- [x] 5.3 `scripts/reconcile_track.py`: `demo` (внедрение, dry-run, apply ×2, безопасность, `healed`, нагрузка) и `cost` (снимок хоста, закрепление CPU, матрица N × режим × 3)
|
||||
- [x] 5.4 Проверка группы: `make check` (Python 3.9, JSON), `make lint`
|
||||
- [ ] 5.5 Процессорное время прохода в отчёте; `cost`: снимок `docker stats` хоста до и после серии, чужой CPU за окно каждого прогона (во всей VM и на закреплённых ядрах), отбраковка и повтор после тишины, отбракованные — в `cost/disturbed/`
|
||||
- [ ] 5.6 `demo`: проход при остановленном S3 — код `1` за ограниченное время, PostgreSQL и bucket не меняются
|
||||
|
||||
## 6. Измерения
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ from messenger.attachments.domain.models import (
|
||||
AttachmentStatus,
|
||||
Quarantine,
|
||||
)
|
||||
from messenger.shared.application.errors import Unavailable
|
||||
from messenger.shared.application.ports import Clock, Logger
|
||||
|
||||
type UnitOfWorkFactory = Callable[[], AttachmentsUnitOfWork]
|
||||
@@ -104,18 +105,22 @@ class Pass:
|
||||
async def run(self) -> None:
|
||||
objects = aiter(self._objects())
|
||||
item = await anext(objects, None)
|
||||
async with asyncio.TaskGroup() as checks:
|
||||
async for row in self._rows():
|
||||
while item is not None and item.key < row.object_key:
|
||||
try:
|
||||
async with asyncio.TaskGroup() as checks:
|
||||
async for row in self._rows():
|
||||
while item is not None and item.key < row.object_key:
|
||||
await self._orphan(item)
|
||||
item = await anext(objects, None)
|
||||
matched = item if item is not None and item.key == row.object_key else None
|
||||
await self._row(row, matched, checks)
|
||||
if matched is not None:
|
||||
item = await anext(objects, None)
|
||||
while item is not None:
|
||||
await self._orphan(item)
|
||||
item = await anext(objects, None)
|
||||
matched = item if item is not None and item.key == row.object_key else None
|
||||
await self._row(row, matched, checks)
|
||||
if matched is not None:
|
||||
item = await anext(objects, None)
|
||||
while item is not None:
|
||||
await self._orphan(item)
|
||||
item = await anext(objects, None)
|
||||
except* Unavailable as failed:
|
||||
error = failed.exceptions[0]
|
||||
raise error from error.__cause__
|
||||
|
||||
async def _timed[ResultT](self, name: str, step: Awaitable[ResultT]) -> ResultT:
|
||||
started = monotonic()
|
||||
|
||||
@@ -22,6 +22,7 @@ from messenger.attachments.infrastructure.postgres import (
|
||||
PostgresSingleRun,
|
||||
)
|
||||
from messenger.migrate import migrate
|
||||
from messenger.shared.application.errors import Unavailable
|
||||
from messenger.shared.infrastructure.clock import MonotonicUtcClock
|
||||
from messenger.shared.infrastructure.postgres import Database
|
||||
from pictures import SAMPLE
|
||||
@@ -271,3 +272,16 @@ async def test_second_pass_is_skipped_while_one_runs(dsn: str) -> None:
|
||||
assert not busy.found
|
||||
assert not free.skipped
|
||||
assert free.fixed["orphan_stale"] == 1
|
||||
|
||||
|
||||
async def test_storage_failure_mid_pass_ends_it_as_unavailable(dsn: str) -> None:
|
||||
async with stand(dsn) as s:
|
||||
await damage(s)
|
||||
|
||||
async def broken() -> None:
|
||||
raise Unavailable("S3 недоступно") from TimeoutError()
|
||||
|
||||
s.store.after_page = broken
|
||||
with pytest.raises(Unavailable) as failed:
|
||||
await s.run(apply=True, deep=True)
|
||||
assert isinstance(failed.value.__cause__, TimeoutError)
|
||||
|
||||
Reference in New Issue
Block a user