mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 20:44:04 +00:00
test_tornado.py: Add websocket closing to tornado tests.
- Extend tornado tests with closing WebSocket connection to avoid leakings warnings. - Mark test_tornado as having 100% coverage. Fixes #3942.
This commit is contained in:
@@ -40,7 +40,10 @@ target_fully_covered = {path for target in [
|
||||
'zerver/lib/users.py',
|
||||
'zerver/lib/webhooks/*.py',
|
||||
'zerver/logging_handlers.py',
|
||||
# As a project, we require 100% test coverage in the views files.
|
||||
'zerver/views/*.py',
|
||||
# Test files should have 100% coverage; test code that isn't run
|
||||
# is likely a bug in the test.
|
||||
'zerver/tests/*.py',
|
||||
# Once we have a nice negative tests system, we can add these:
|
||||
# 'zerver/webhooks/*/*.py',
|
||||
@@ -85,9 +88,6 @@ not_yet_fully_covered = {
|
||||
'zerver/lib/push_notifications.py',
|
||||
'zerver/lib/upload.py',
|
||||
'zerver/models.py',
|
||||
# Test files should have full coverage; it's a bug in the test if
|
||||
# they don't! There are open issues for all of these.
|
||||
'zerver/tests/test_tornado.py',
|
||||
}
|
||||
|
||||
enforce_fully_covered = sorted(target_fully_covered - not_yet_fully_covered)
|
||||
|
||||
@@ -40,7 +40,6 @@ class WebSocketBaseTestCase(AsyncHTTPTestCase, ZulipTestCase):
|
||||
|
||||
def setUp(self):
|
||||
# type: () -> None
|
||||
#
|
||||
settings.RUNNING_INSIDE_TORNADO = True
|
||||
super(WebSocketBaseTestCase, self).setUp()
|
||||
|
||||
@@ -61,15 +60,14 @@ class WebSocketBaseTestCase(AsyncHTTPTestCase, ZulipTestCase):
|
||||
|
||||
@gen.coroutine
|
||||
def close(self, ws):
|
||||
# type: (Any) -> Generator[None, Any, None]
|
||||
# type: (Any) -> None
|
||||
"""Close a websocket connection and wait for the server side.
|
||||
|
||||
If we don't wait here, there are sometimes leak warnings in the
|
||||
tests.
|
||||
"""
|
||||
ws.close()
|
||||
yield self.close_future
|
||||
|
||||
self.wait()
|
||||
|
||||
class TornadoTestCase(WebSocketBaseTestCase):
|
||||
def get_app(self):
|
||||
@@ -190,6 +188,7 @@ class TornadoTestCase(WebSocketBaseTestCase):
|
||||
ws = yield self.ws_connect('/sockjs/366/v8nw22qe/websocket', cookie_header=cookie_header)
|
||||
response = yield ws.read_message()
|
||||
self.assertEqual(response, 'o')
|
||||
self.close(ws)
|
||||
|
||||
@gen_test
|
||||
def test_tornado_auth(self):
|
||||
@@ -223,6 +222,7 @@ class TornadoTestCase(WebSocketBaseTestCase):
|
||||
},
|
||||
"type": "response"}
|
||||
])
|
||||
self.close(ws)
|
||||
|
||||
@gen_test
|
||||
def test_sending_private_message(self):
|
||||
@@ -257,6 +257,7 @@ class TornadoTestCase(WebSocketBaseTestCase):
|
||||
ack_resp = yield ws.read_message()
|
||||
msg_resp = yield ws.read_message()
|
||||
self._check_message_sending(request_id, ack_resp, msg_resp, user_profile, queue_events_data)
|
||||
self.close(ws)
|
||||
|
||||
@gen_test
|
||||
def test_sending_stream_message(self):
|
||||
@@ -291,3 +292,4 @@ class TornadoTestCase(WebSocketBaseTestCase):
|
||||
ack_resp = yield ws.read_message()
|
||||
msg_resp = yield ws.read_message()
|
||||
self._check_message_sending(request_id, ack_resp, msg_resp, user_profile, queue_events_data)
|
||||
self.close(ws)
|
||||
|
||||
Reference in New Issue
Block a user