cmvr-visual/backend/tests/test_pool_waiters.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

79 lines
2.9 KiB
Python

import asyncio
import pytest
from sqlalchemy import select
from app.models import Job
from app.models import Execution
async def submit_jobs(system, task_type, count):
jobs = []
for index in range(count):
response = await system.client.post(
"/api/jobs",
json={
"task_type": task_type,
"input": {"prompt": f"request {index}"},
},
)
assert response.status_code == 202, response.text
jobs.append(response.json()["jobs"][0]["id"])
return jobs
@pytest.mark.asyncio
async def test_fifty_quarantined_qwen_jobs_cannot_block_new_speech(system, monkeypatch):
system.settings.max_creation_commands_per_minute = 100
system.settings.tts_base_url = "http://fake-private-tts"
coordinator = system.app.state.coordinator
coordinator._blocked_pools.add("qwen_http")
qwen_jobs = await submit_jobs(system, "math.solve", 50)
await coordinator.run_once(force=True)
async with system.app.state.db.session() as session:
assert not (await session.scalars(select(Execution))).all()
waiting = (await session.scalars(select(Job).where(Job.id.in_(qwen_jobs)))).all()
assert all(job.current_execution_id is None for job in waiting)
started = asyncio.Event()
boundary = system.provider.run_cpu
calls = []
async def speech_boundary(task_type, *args):
calls.append(task_type)
assert task_type == "audio.speech", "Quarantined Qwen must not execute"
started.set()
return await boundary(task_type, *args)
monkeypatch.setattr(system.provider, "run_cpu", speech_boundary)
speech_job = (await submit_jobs(system, "audio.speech", 1))[0]
await coordinator.run_once(force=True)
await asyncio.wait_for(started.wait(), 3)
await asyncio.wait_for(coordinator._cpu[speech_job], 3)
assert calls == ["audio.speech"]
assert "qwen_http" in coordinator._blocked_pools
assert len(set(qwen_jobs).intersection(coordinator._cpu)) <= 25
assert len(coordinator._cpu) <= 50
async with system.app.state.db.session() as session:
assert (await session.get(Job, speech_job)).state == "succeeded"
assert not (
await session.scalars(select(Execution).where(Execution.job_id.in_(qwen_jobs)))
).all()
@pytest.mark.asyncio
async def test_one_pool_has_a_bounded_pending_coroutine_queue(system):
system.settings.max_creation_commands_per_minute = 100
coordinator = system.app.state.coordinator
coordinator._blocked_pools.add("qwen_http")
jobs = await submit_jobs(system, "math.solve", 26)
await coordinator.run_once(force=True)
assert len(coordinator._cpu) == 25
assert system.provider.cpu_runs == 0
async with system.app.state.db.session() as session:
assert len((await session.scalars(select(Job).where(Job.id.in_(jobs)))).all()) == 26
assert not (await session.scalars(select(Execution))).all()