74 lines
2.8 KiB
Python
74 lines
2.8 KiB
Python
|
|
import asyncio
|
||
|
|
|
||
|
|
import pytest
|
||
|
|
from sqlalchemy import select
|
||
|
|
|
||
|
|
from app.models import Job
|
||
|
|
from app.v2_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()
|