"""HTTP size limit and scheduler lock behaviour.""" from __future__ import annotations from unittest.mock import AsyncMock, patch import httpx import pytest import respx from app.probes.http import probe_http from app.scheduler import _locks, job_import_sources @pytest.mark.asyncio @respx.mock async def test_http_response_size_limit(): url = "http://tracker.example:80/announce" big = b"x" * 2000 def _handler(request: httpx.Request) -> httpx.Response: return httpx.Response(200, content=big) respx.route(method="GET", host="tracker.example").mock(side_effect=_handler) async with httpx.AsyncClient() as client: outcome = await probe_http( url, client=client, max_bytes=1000, resolved_ips=["1.1.1.1"], ) assert outcome.response_valid is False assert outcome.error_kind == "too_large" @pytest.mark.asyncio async def test_scheduler_skips_overlapping_import(): # Hold the import lock and ensure job returns immediately without work assert not _locks["import"].locked() await _locks["import"].acquire() try: with patch("app.scheduler.import_all_sources", new_callable=AsyncMock) as mocked: await job_import_sources() mocked.assert_not_called() finally: _locks["import"].release()