cmvr-visual/tts/tests/test_editor_queue.py
zhanghao 88cf14d794 feat: consolidate story studio and editable automatic production
Restructure backend and frontend modules; add story, library, and editor schema migrations.

Support editable automatic production, manual confirmation modes, account and user lifecycle management, compact container scrolling, consistent forms, and per-task result previews.

Update inference and TTS scheduling, deployment guidance, and regression coverage; remove obsolete standalone pages and temporary acceptance artifacts.
2026-11-14 14:07:26 +08:00

43 lines
1.8 KiB
Python

import asyncio
import sys
import tempfile
from pathlib import Path
import pytest
from fastapi import HTTPException
sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
from tts.app import SpeechRequest, TTSSettings, create_app
def test_queue_deadline_never_starts_waiting_model_and_cleans_request():
async def scenario(root):
model = root / "models"
(model / "voices").mkdir(parents=True)
for name in ("config.json", "kokoro-v1_0.pth", "voices/zf_xiaobei.pt", "voices/zm_yunxi.pt"):
(model / name).write_bytes(b"fixture")
settings = TTSSettings("fixture-key", model, root / "work", queue_timeout_seconds=.01)
started, calls = asyncio.Event(), []
async def synthesize(body, destination, settings):
calls.append(body.input)
started.set()
await asyncio.Event().wait()
class Connection:
async def is_disconnected(self):
return False
endpoint = next(r.endpoint for r in create_app(settings, synthesize=synthesize).routes if r.path == "/v1/audio/speech")
first = asyncio.create_task(endpoint(SpeechRequest(input="first"), Connection()))
try:
await started.wait()
with pytest.raises(HTTPException) as error:
await endpoint(SpeechRequest(input="queued"), Connection())
assert error.value.status_code == 503
assert calls == ["first"]
assert len(list(settings.work_dir.iterdir())) == 1
finally:
first.cancel()
await asyncio.gather(first, return_exceptions=True)
assert list(settings.work_dir.iterdir()) == []
with tempfile.TemporaryDirectory(prefix="tq-") as directory:
asyncio.run(scenario(Path(directory)))