fix: handle malformed JSON payloads in worker with error logging
This commit is contained in:
parent
ca97ff1aa8
commit
89fbdb37bd
2 changed files with 23 additions and 2 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue