Finish external HTTP client resilience: add shared aiohttp config, retry support, and update task status
This commit is contained in:
@@ -125,6 +125,27 @@ class TestPreview:
|
||||
with pytest.raises(ValueError, match="HTTP 404"):
|
||||
await blocklist_service.preview_source("https://bad.test/", session)
|
||||
|
||||
async def test_preview_retries_transient_errors(self) -> None:
|
||||
"""preview_source retries transient network failures before succeeding."""
|
||||
content = "1.2.3.4\n"
|
||||
mock_resp = AsyncMock()
|
||||
mock_resp.status = 200
|
||||
mock_resp.text = AsyncMock(return_value=content)
|
||||
mock_resp.content = AsyncMock()
|
||||
mock_resp.content.read = AsyncMock(return_value=content.encode())
|
||||
|
||||
mock_ctx = AsyncMock()
|
||||
mock_ctx.__aenter__.return_value = mock_resp
|
||||
mock_ctx.__aexit__.return_value = False
|
||||
|
||||
session = MagicMock()
|
||||
session.get = MagicMock(side_effect=[Exception("connection reset"), mock_ctx])
|
||||
|
||||
result = await blocklist_service.preview_source("https://test.test/ips.txt", session)
|
||||
|
||||
assert result.valid_count == 1
|
||||
assert session.get.call_count == 2
|
||||
|
||||
async def test_preview_limits_entries(self) -> None:
|
||||
"""preview_source caps entries to sample_lines."""
|
||||
ips = "\n".join(f"1.2.3.{i}" for i in range(50))
|
||||
|
||||
Reference in New Issue
Block a user