import asyncio from app.models import Job async def test_shutdown_preserves_cpu_waiter_that_never_started_provider(system): system.settings.tts_base_url='http://test-tts' system.provider.cpu_wait=True ids=[] for prompt in ('first','second'): response=await system.client.post('/api/jobs',json={'task_type':'audio.speech','input':{'prompt':prompt}}) assert response.status_code==202 ids.append(response.json()['jobs'][0]['id']) coordinator=system.app.state.coordinator await coordinator.run_once(force=True) for _ in range(100): async with system.app.state.db.session() as session: waiter=await session.get(Job,ids[1]) if waiter.work_attempt and system.provider.cpu_runs==1:break await asyncio.sleep(.01) assert waiter.current_execution_id is None await coordinator.close() async with system.app.state.db.session() as session: waiter=await session.get(Job,ids[1]) assert waiter.state=='queued' and waiter.error_json is None assert waiter.current_execution_id is None assert system.provider.cpu_runs==1