test_slice_progress_timeout_detail.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. """A slow slice-progress answer is reported as slow, not as an unreachable sidecar (TO-C14).
  2. A heavy slice can keep the sidecar from answering its progress poll within
  3. 5 s; httpx's ReadTimeout is a RequestError, so the proxy said "Slicer sidecar
  4. unreachable". The poller retries on 503 either way; the text was wrong.
  5. """
  6. from unittest.mock import AsyncMock, MagicMock, patch
  7. import httpx
  8. import pytest
  9. from fastapi import HTTPException
  10. from backend.app.api.routes import slicer_presets
  11. pytestmark = pytest.mark.asyncio
  12. async def _poll(error: Exception) -> HTTPException:
  13. client = MagicMock()
  14. client.__aenter__ = AsyncMock(return_value=client)
  15. client.__aexit__ = AsyncMock(return_value=False)
  16. client.get = AsyncMock(side_effect=error)
  17. with (
  18. patch.object(slicer_presets, "_resolve_slicer_api_url", AsyncMock(return_value="http://sidecar:3000")),
  19. patch("httpx.AsyncClient", return_value=client),
  20. pytest.raises(HTTPException) as raised,
  21. ):
  22. await slicer_presets.get_preview_slice_progress(request_id="abc", db=MagicMock(), _=(None, True))
  23. return raised.value
  24. async def test_a_timeout_says_the_sidecar_is_busy():
  25. refused = await _poll(httpx.ReadTimeout("read timed out"))
  26. assert refused.status_code == 503
  27. assert "unreachable" not in refused.detail
  28. assert "did not answer in time" in refused.detail
  29. async def test_a_refused_connection_is_still_unreachable():
  30. refused = await _poll(httpx.ConnectError("connection refused"))
  31. assert (refused.status_code, refused.detail) == (503, "Slicer sidecar unreachable")