From af699500b7b162b1c6d9fdd3bc350593664653c0 Mon Sep 17 00:00:00 2001 From: derAnfaenger Date: Fri, 13 Oct 2017 17:53:02 +0200 Subject: [PATCH] tests: Add option to call queue processor consumer. This makes tests of queue processors more realistic, by adding a parameter to `queue_json_publish` that calls a queue's consumer function if accessed in a test. Fixes part of #6542. --- zerver/lib/queue.py | 8 ++++++-- zerver/tornado/event_queue.py | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/zerver/lib/queue.py b/zerver/lib/queue.py index 0a649463d8..cd7f9848e5 100644 --- a/zerver/lib/queue.py +++ b/zerver/lib/queue.py @@ -297,12 +297,16 @@ def get_queue_client(): # randomly close. queue_lock = threading.RLock() -def queue_json_publish(queue_name, event, processor): - # type: (str, Union[Mapping[str, Any], str], Callable[[Any], None]) -> None +def queue_json_publish(queue_name, event, processor, call_consume_in_tests=False): + # type: (str, Union[Dict[str, Any], str], Callable[[Any], None], bool) -> None # most events are dicts, but zerver.middleware.write_log_line uses a str with queue_lock: if settings.USING_RABBITMQ: get_queue_client().json_publish(queue_name, event) + elif call_consume_in_tests: + # Must be imported here: A top section import leads to obscure not-defined-ish errors. + from zerver.worker.queue_processors import get_worker + get_worker(queue_name).consume_wrapper(event) # type: ignore # https://github.com/python/mypy/issues/3360 else: processor(event) diff --git a/zerver/tornado/event_queue.py b/zerver/tornado/event_queue.py index 559c032c3c..a1db7c26f5 100644 --- a/zerver/tornado/event_queue.py +++ b/zerver/tornado/event_queue.py @@ -942,7 +942,7 @@ def send_notification_http(data): process_notification(data) def send_notification(data): - # type: (Mapping[str, Any]) -> None + # type: (Dict[str, Any]) -> None queue_json_publish("notify_tornado", data, send_notification_http) def send_event(event, users):