mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 09:20:22 +08:00
refactor(task): 拆分 TaskService 并重构任务生命周期
- 将 task 公共协议/上下文/异常/schema 下沉到 core,并迁移 polling 目录 - 新增 execute/submit/video 子模块,拆分同步执行、异步提交流程、错误处理与视频任务操作 - 收敛 TaskService 为门面编排,内部委派到 SyncTaskExecutionService、AsyncTaskSubmitService、VideoTaskOperationsService - 重构 main 生命周期管理:引入 LifecycleState,拆分启动与关闭流程 - 删除未使用的 TaskExecuteFacadeService 与 TaskSubmitFacadeService Closes #201 Co-authored-by: AAEE86 <ppk0227@hotmail.com>
This commit is contained in:
44
tests/services/test_video_ops_cancel_delegate.py
Normal file
44
tests/services/test_video_ops_cancel_delegate.py
Normal file
@@ -0,0 +1,44 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import AsyncMock, MagicMock
|
||||
|
||||
import pytest
|
||||
from fastapi import HTTPException
|
||||
|
||||
from src.services.task.core.exceptions import TaskNotFoundError
|
||||
from src.services.task.video.operations import VideoTaskOperationsService
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_video_ops_cancel_delegates_to_cancel_ops() -> None:
|
||||
svc = VideoTaskOperationsService(MagicMock())
|
||||
task = SimpleNamespace(id="task-1")
|
||||
|
||||
svc._get_video_task_for_user = MagicMock(return_value=task) # type: ignore[attr-defined, method-assign]
|
||||
svc._cancel_ops.cancel_task = AsyncMock(return_value={"ok": True}) # type: ignore[attr-defined, method-assign]
|
||||
|
||||
result = await svc.cancel(
|
||||
"task-1",
|
||||
user_id="user-1",
|
||||
original_headers={"x-test": "1"},
|
||||
)
|
||||
|
||||
assert result == {"ok": True}
|
||||
svc._cancel_ops.cancel_task.assert_awaited_once_with( # type: ignore[attr-defined]
|
||||
task=task,
|
||||
task_id="task-1",
|
||||
original_headers={"x-test": "1"},
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_video_ops_cancel_maps_not_found_to_http_404() -> None:
|
||||
svc = VideoTaskOperationsService(MagicMock())
|
||||
svc._get_video_task_for_user = MagicMock(side_effect=TaskNotFoundError("missing")) # type: ignore[attr-defined, method-assign]
|
||||
|
||||
with pytest.raises(HTTPException) as excinfo:
|
||||
await svc.cancel("missing", user_id="user-1")
|
||||
|
||||
assert excinfo.value.status_code == 404
|
||||
assert excinfo.value.detail == "Video task not found"
|
||||
Reference in New Issue
Block a user