mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 23:47:41 +08:00
fix: await durable subscribe deletion reports
This commit is contained in:
@@ -116,6 +116,28 @@ def _command(
|
||||
)
|
||||
|
||||
|
||||
def _async_report_command(candidate, calls, result=True, error=None, outbox=None):
|
||||
"""构造异步统计 reporter,验证命令可等待真实远端确认。"""
|
||||
async def publish(payload):
|
||||
"""记录删除事件。"""
|
||||
calls.append(("event", payload["subscribe_id"], payload))
|
||||
|
||||
async def report(payload):
|
||||
"""记录异步统计并按需返回未确认或抛错。"""
|
||||
calls.append(("report", payload))
|
||||
if error:
|
||||
raise error
|
||||
return result
|
||||
|
||||
return DeleteSubscribeCommand(
|
||||
repository=_Repository(candidate, calls),
|
||||
unit_of_work=_UnitOfWork(calls),
|
||||
publish_deleted=publish,
|
||||
report_deleted=report,
|
||||
outbox=outbox,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_owner_delete_commits_before_event_and_report():
|
||||
"""owner 删除成功时必须先提交,再按原顺序发送事件和上报。"""
|
||||
@@ -265,6 +287,64 @@ async def test_delete_outbox_stage_failure_rolls_back_business_delete():
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_async_reporter_completes_report_intent_only_after_confirmation():
|
||||
"""异步 reporter 确认成功后才允许收口统计 intent。"""
|
||||
calls = []
|
||||
command = _async_report_command(_candidate(), calls, outbox=_Outbox(calls))
|
||||
|
||||
assert await command.execute(
|
||||
7,
|
||||
SubscribeDeletionActor(username="alice", is_superuser=False),
|
||||
) is True
|
||||
|
||||
assert [call[0] for call in calls] == [
|
||||
"get", "delete", "outbox_stage", "outbox_stage", "commit",
|
||||
"event", "outbox_complete", "report", "outbox_complete",
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_async_reporter_false_keeps_report_intent_pending():
|
||||
"""异步 reporter 未确认时必须保留待重试统计 intent。"""
|
||||
calls = []
|
||||
command = _async_report_command(_candidate(), calls, result=False, outbox=_Outbox(calls))
|
||||
|
||||
with pytest.raises(RuntimeError, match="未确认"):
|
||||
await command.execute(
|
||||
7,
|
||||
SubscribeDeletionActor(username="alice", is_superuser=False),
|
||||
)
|
||||
|
||||
assert [call[0] for call in calls] == [
|
||||
"get", "delete", "outbox_stage", "outbox_stage", "commit",
|
||||
"event", "outbox_complete", "report",
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_async_reporter_error_keeps_report_intent_pending():
|
||||
"""异步 reporter 异常时必须保留待重试统计 intent。"""
|
||||
calls = []
|
||||
command = _async_report_command(
|
||||
_candidate(),
|
||||
calls,
|
||||
error=RuntimeError("remote failed"),
|
||||
outbox=_Outbox(calls),
|
||||
)
|
||||
|
||||
with pytest.raises(RuntimeError, match="remote failed"):
|
||||
await command.execute(
|
||||
7,
|
||||
SubscribeDeletionActor(username="alice", is_superuser=False),
|
||||
)
|
||||
|
||||
assert [call[0] for call in calls] == [
|
||||
"get", "delete", "outbox_stage", "outbox_stage", "commit",
|
||||
"event", "outbox_complete", "report",
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_repository_candidate_uses_loaded_orm_snapshot(monkeypatch):
|
||||
"""DB 适配器只向应用层暴露权限字段和完整列快照。"""
|
||||
|
||||
Reference in New Issue
Block a user