fix: handle malformed JSON payloads in worker with error logging

This commit is contained in:
counterweight 2025-12-21 23:24:28 +01:00
parent ca97ff1aa8
commit 89fbdb37bd
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
2 changed files with 23 additions and 2 deletions

View file

@ -171,3 +171,20 @@ class TestRandomNumberJobHandler:
# Should not have called execute
mock_conn.execute.assert_not_called()
@pytest.mark.asyncio
async def test_malformed_json_payload_does_not_insert(self):
"""Verify no insert happens with malformed JSON payload."""
from worker import process_random_number_job
job = MagicMock()
job.id = 123
job.payload = b"not valid json {"
mock_conn = AsyncMock()
mock_pool = create_mock_pool(mock_conn)
await process_random_number_job(job, mock_pool)
# Should not have called execute
mock_conn.execute.assert_not_called()