f032152eaa
CI/CD Pipeline / Check push changed paths (pull_request) Has been skipped
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 2s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 3s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Validate - Style (pull_request) Has been skipped
CI/CD Pipeline / Validate - Security (pull_request) Has been skipped
CI/CD Pipeline / Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Has been skipped
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 42s
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 48s
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 2m23s
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / CI Gate (pull_request) Successful in 3s
CI/CD Pipeline / Canary Release to Production (pull_request) Has been skipped
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 2m17s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m24s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Has been skipped
AI Code Review / AI Code Review (pull_request) Successful in 6m51s
CI/CD Pipeline / Check if frontend-only change (push) Has been skipped
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (push) Successful in 1s
CI/CD Pipeline / Check push changed paths (push) Successful in 2s
CI/CD Pipeline / Frontend Lint (push) Has been skipped
CI/CD Pipeline / PR Build API Image (push) Has been skipped
CI/CD Pipeline / PR Build Web Image (push) Has been skipped
CI/CD Pipeline / PR Build Worker Image (push) Has been skipped
CI/CD Pipeline / Integration Tests (push) Successful in 4m7s
CI/CD Pipeline / Build Staging API Image (push) Successful in 4m14s
CI/CD Pipeline / Validate - Python (mypy + alembic) (push) Successful in 4m28s
CI/CD Pipeline / Build Staging Worker Image (push) Successful in 4m47s
CI/CD Pipeline / Build Staging Web Image (push) Successful in 4m49s
CI/CD Pipeline / Retag skipped Staging API Image (push) Has been skipped
CI/CD Pipeline / Retag skipped Staging Web Image (push) Has been skipped
CI/CD Pipeline / Retag skipped Staging Worker Image (push) Has been skipped
CI/CD Pipeline / Validate - Style (push) Successful in 5m7s
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 6m58s
CI/CD Pipeline / Unit Tests (push) Successful in 12m19s
CI/CD Pipeline / Validate - Security (push) Successful in 13m1s
CI/CD Pipeline / Build Production Web Image (push) Has been skipped
CI/CD Pipeline / Build Production API Image (push) Has been skipped
CI/CD Pipeline / Build Production Worker Image (push) Has been skipped
CI/CD Pipeline / CI Gate (push) Has been skipped
CI/CD Pipeline / Deploy Production (push) Has been skipped
CI/CD Pipeline / Production Browser E2E (push) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Failing after 10m9s
CI/CD Pipeline / Staging E2E Tests (push) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (push) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (push) Has been skipped
CI/CD Pipeline / Canary Release to Production (push) Has been skipped
Co-authored-by: xiaoxia <dev@xiaoxiajianji.com> Co-committed-by: xiaoxia <dev@xiaoxiajianji.com>
90 lines
2.6 KiB
Python
90 lines
2.6 KiB
Python
"""GPU Worker 路由单测 — #2009 取消链路.
|
|
|
|
直接调用路由函数(不经 HTTP 栈),显式注入 svc / _token 以跳过 Depends。
|
|
CI 增量映射: gpu_lipsync.py (route) → test_gpu_lipsync_routes.py
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
import pytest
|
|
|
|
|
|
def _payload(**overrides):
|
|
from app.schemas.gpu_lipsync import GpuWorkerRegisterRequest
|
|
|
|
data = {
|
|
"worker_id": "w-1",
|
|
"hostname": "gpu-host",
|
|
"gpu_name": "RTX3060",
|
|
"free_vram_mb": 10000,
|
|
"capabilities": json.dumps({"musetalk": True}),
|
|
}
|
|
data.update(overrides)
|
|
return GpuWorkerRegisterRequest(**data)
|
|
|
|
|
|
def test_register_returns_cancel_task_true_when_cancelled():
|
|
"""心跳接口在任务已取消时必须把 cancel_task=True 透传给 Worker."""
|
|
fake_worker = MagicMock()
|
|
fake_worker.worker_id = "w-1"
|
|
fake_worker.hostname = "gpu-host"
|
|
fake_worker.gpu_name = "RTX3060"
|
|
fake_worker.free_vram_mb = 10000
|
|
fake_worker.capabilities = "musetalk"
|
|
fake_svc = MagicMock()
|
|
fake_svc.register_worker.return_value = (fake_worker, True)
|
|
|
|
from app.api.routes.gpu_lipsync import register_worker as route
|
|
|
|
resp = route(_payload(task_id="task-cancelled"), svc=fake_svc, _token="t")
|
|
|
|
assert resp.cancel_task is True
|
|
assert resp.ok is True
|
|
fake_svc.register_worker.assert_called_once()
|
|
kwargs = fake_svc.register_worker.call_args.kwargs
|
|
assert kwargs["task_id"] == "task-cancelled"
|
|
|
|
|
|
def test_register_returns_cancel_task_false_normal():
|
|
"""正常心跳 cancel_task=False."""
|
|
fake_worker = MagicMock()
|
|
fake_worker.worker_id = "w-1"
|
|
fake_worker.hostname = "gpu-host"
|
|
fake_worker.gpu_name = "RTX3060"
|
|
fake_worker.free_vram_mb = 10000
|
|
fake_worker.capabilities = "musetalk"
|
|
fake_svc = MagicMock()
|
|
fake_svc.register_worker.return_value = (fake_worker, False)
|
|
|
|
from app.api.routes.gpu_lipsync import register_worker as route
|
|
|
|
resp = route(_payload(), svc=fake_svc, _token="t")
|
|
|
|
assert resp.cancel_task is False
|
|
|
|
|
|
def test_cancel_route_accepts_processing_status():
|
|
"""cancel 路由允许 processing 状态(GPU 推理中),不再 400。"""
|
|
fake_job = MagicMock()
|
|
fake_job.status = "cancelled"
|
|
|
|
svc = MagicMock()
|
|
svc.cancel_job.return_value = fake_job
|
|
|
|
current_user = MagicMock()
|
|
current_user.user.id = "u1"
|
|
|
|
from app.api.routes.lipsync import cancel_lipsync_job as route
|
|
|
|
result = route("job-1", current_user, svc)
|
|
|
|
svc.cancel_job.assert_called_once_with("job-1", "u1")
|
|
assert result.status == "cancelled"
|
|
|
|
|
|
if __name__ == "__main__":
|
|
pytest.main([__file__, "-q"])
|