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

42 lines
1.7 KiB
Python

import asyncio
from types import SimpleNamespace
import httpx
import pytest
from app.adapters.provider.client import Provider
from app.domain.errors import MediaError
@pytest.mark.asyncio
async def test_qwen_cold_load_uses_independent_transport_and_total_timeout():
seen = []
async def upstream(request):
seen.append(request.extensions['timeout']['read'])
await asyncio.sleep(1.08)
return httpx.Response(200, json={'choices': [{'message': {'content': '2'}}]})
settings = SimpleNamespace(request_timeout_seconds=.01, qwen_timeout_seconds=2,
qwen_base_url='http://qwen.test/v1', qwen_model='example', qwen_api_key='')
provider = Provider(settings)
await provider.client.aclose()
provider.client = httpx.AsyncClient(transport=httpx.MockTransport(upstream), timeout=.01)
try:
assert await provider._chat([{'role':'user', 'content':'1+1'}]) == '2'
assert seen == [2], 'Qwen must override the HTTP read timeout as well as the total deadline'
with pytest.raises(MediaError, match='超时'):
await provider._json('GET', 'http://qwen.test/slow-control')
finally:
await provider.aclose()
def test_qwen_timeout_config_is_separate_from_normal_api_timeout(monkeypatch):
from app.core.config import Settings
monkeypatch.setenv('CMVR_MODE', 'test')
monkeypatch.setenv('DATABASE_URL', 'sqlite+aiosqlite:///:memory:')
assert hasattr(Settings.from_env(), 'qwen_timeout_seconds'), 'Qwen cold startup needs its own configured wait'
monkeypatch.setenv('QWEN_TIMEOUT_SECONDS', '600')
monkeypatch.setenv('REQUEST_TIMEOUT_SECONDS', '3')
settings = Settings.from_env()
assert settings.qwen_timeout_seconds == 600
assert settings.request_timeout_seconds == 3