"""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()