mirror of https://github.com/zulip/zulip.git
queue_processors: Add error coverage for MessageSenderWorker.
This commit is contained in:
parent
d9571698f2
commit
032fad2cf1
|
@ -37,6 +37,7 @@ from zerver.tornado.views import get_events_backend
|
|||
from http.cookies import SimpleCookie
|
||||
import urllib.parse
|
||||
|
||||
from unittest.mock import patch
|
||||
from typing import Any, Callable, Dict, Generator, Optional, Text, List, cast
|
||||
|
||||
class TornadoWebTestCase(AsyncHTTPTestCase, ZulipTestCase):
|
||||
|
@ -407,3 +408,52 @@ class TornadoTestCase(WebSocketBaseTestCase):
|
|||
msg_resp = yield ws.read_message()
|
||||
self._check_message_sending(request_id, ack_resp, msg_resp, user_profile, queue_events_data)
|
||||
yield self.close(ws)
|
||||
|
||||
@gen_test
|
||||
def test_sending_message_error(self) -> Any:
|
||||
user_profile = self.example_user('hamlet')
|
||||
cookies = self._get_cookies(user_profile)
|
||||
cookie_header = self.get_cookie_header(cookies)
|
||||
queue_events_data = self._get_queue_events_data(user_profile.email)
|
||||
ws = yield self.ws_connect('/sockjs/366/v8nw22qe/websocket', cookie_header=cookie_header)
|
||||
yield ws.read_message()
|
||||
yield self._websocket_auth(ws, queue_events_data, cookies)
|
||||
request_id = ':'.join((queue_events_data['response']['queue_id'], '1'))
|
||||
user_message = {
|
||||
"req_id": request_id,
|
||||
"type": "request",
|
||||
"request": {
|
||||
"client": "website",
|
||||
"type": "stream",
|
||||
"subject": "Stream message",
|
||||
"stream": "Denmark",
|
||||
"private_message_recipient": "",
|
||||
"content": "hello",
|
||||
"sender_id": user_profile.id,
|
||||
"queue_id": queue_events_data['response']['queue_id'],
|
||||
"to": ujson.dumps(["Denmark"]),
|
||||
"reply_to": self.example_email('hamlet'),
|
||||
"local_id": -1
|
||||
}
|
||||
}
|
||||
user_message_str = ujson.dumps(user_message)
|
||||
ws.write_message(ujson.dumps([user_message_str]))
|
||||
|
||||
def wrap_get_response(request: HttpRequest) -> HttpResponse:
|
||||
request._log_data = {'bugdown_requests_start': 0,
|
||||
'time_started': 0,
|
||||
'bugdown_time_start': 0,
|
||||
'remote_cache_time_start': 0,
|
||||
'remote_cache_requests_start': 0,
|
||||
'startup_time_delta': 0}
|
||||
|
||||
class ResponseObject(object):
|
||||
def __init__(self) -> None:
|
||||
self.content = '{"msg":"","id":0,"result":"error"}'.encode('utf8')
|
||||
return ResponseObject()
|
||||
# Simulate an error response to cover the respective code paths.
|
||||
with patch('django.core.handlers.base.BaseHandler.get_response', wraps=wrap_get_response), \
|
||||
patch('django.db.connection.is_usable', return_value=False), \
|
||||
patch('os.kill', side_effect=OSError()):
|
||||
yield ws.read_message()
|
||||
yield self.close(ws)
|
||||
|
|
Loading…
Reference in New Issue