Merge Critical Corrections plan 002: two API processes, worker drains its queue
All checks were successful
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Successful in 6m11s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Successful in 59s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-09 16:46:57 -03:00
6 changed files with 60 additions and 4 deletions

View File

@@ -0,0 +1,27 @@
"""The outbox worker drains a backlog instead of one job per second (item 9).
Run from the repository root: python3 -m unittest tests.test_worker_drain -v.
The worker imports psycopg and boto3, so a host without the API image's
dependencies cannot import it; CI runs this in the api container.
"""
import unittest
from unittest import mock
from app import worker
class WorkerDrainTest(unittest.TestCase):
def test_drain_stops_when_the_queue_is_empty(self):
with mock.patch.object(worker, 'tick',
side_effect=[True, True, True, False]) as tick:
worker.drain()
self.assertEqual(tick.call_count, 4)
def test_drain_stops_at_the_limit(self):
with mock.patch.object(worker, 'tick', return_value=True) as tick:
worker.drain()
self.assertEqual(tick.call_count, 50)
if __name__ == '__main__':
unittest.main()