Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
queue: Set TornadoQueueClient's prefetch count once per channel.
Alex Vandiver5ba8c54ad280
diff --git a/zerver/lib/queue.py b/zerver/lib/queue.pyindex 93499870a19..dacd55d10f6 100644--- a/zerver/lib/queue.py+++ b/zerver/lib/queue.py@@ -350,6 +350,7 @@ class TornadoQueueClient(QueueClient[Channel]):def _on_channel_open(self, channel: Channel) -> None:self.channel = channel+ self.channel.basic_qos(prefetch_count=self.prefetch)for callback in self._on_open_cbs:callback(channel)self._reconnect_consumer_callbacks()@@ -362,13 +363,9 @@ class TornadoQueueClient(QueueClient[Channel]):@overridedef ensure_queue(self, queue_name: str, callback: Callable[[Channel], object]) -> None:- def set_qos(frame: Any) -> None:- assert self.channel is not None- self.queues.add(queue_name)- self.channel.basic_qos(prefetch_count=self.prefetch, callback=finish)-def finish(frame: Any) -> None:assert self.channel is not None+ self.queues.add(queue_name)callback(self.channel)if queue_name not in self.queues:@@ -379,7 +376,7 @@ class TornadoQueueClient(QueueClient[Channel]):returnassert self.channel is not None- self.channel.queue_declare(queue=queue_name, durable=True, callback=set_qos)+ self.channel.queue_declare(queue=queue_name, durable=True, callback=finish)else:assert self.channel is not Nonecallback(self.channel)diff --git a/zerver/tests/test_queue.py b/zerver/tests/test_queue.pyindex 7042ab1af30..2b0929dd772 100644--- a/zerver/tests/test_queue.py+++ b/zerver/tests/test_queue.py@@ -16,6 +16,27 @@ from zerver.lib.test_classes import ZulipTestCaseclass TestTornadoQueueClient(ZulipTestCase):+ @mock.patch("zerver.lib.queue.ExceptionFreeTornadoConnection", autospec=True)+ def test_register_consumer(self, mock_cxn: mock.MagicMock) -> None:+ connection = TornadoQueueClient()+ connection.start_json_consumer("test_suite", lambda events: None)++ channel = mock.MagicMock()+ channel.queue_declare.side_effect = lambda queue, durable, callback: callback(None)+ with self.assertLogs("zulip.queue", "INFO") as m:+ connection._on_channel_open(channel)+ self.assert_length(m.output, 2)+ self.assertTrue(m.output[0].endswith(" to queue test_suite"))+ self.assertEqual(m.output[1], "INFO:zulip.queue:TornadoQueueClient connected")+ self.assertEqual(+ channel.mock_calls,+ [+ mock.call.basic_qos(prefetch_count=100),+ mock.call.queue_declare(queue="test_suite", durable=True, callback=mock.ANY),+ mock.call.basic_consume("test_suite", mock.ANY, consumer_tag=mock.ANY),+ ],+ )+@mock.patch("zerver.lib.queue.ExceptionFreeTornadoConnection", autospec=True)def test_on_open_closed(self, mock_cxn: mock.MagicMock) -> None:with self.assertLogs("zulip.queue", "WARNING") as m: