mirror of https://github.com/zulip/zulip.git
tests: Move clear_client_event_queues_for_testing to ZulipTestCase.
Following recent testing flakes that were traced down to this not having been called causing `receiver_is_off_zulip` to depend on test ordering, it makes sense to centralize this. I think it should always have been in ZulipTestCase; it appears the reason it wasn't from the beginning was that originally only test_events.py interacted with it, and do_test there still needs to call this directly (because it can be called multiple times within a single test). And then we did the wrong thing as expanded use of Tornado event_queue code in tests to more of the codebase.
This commit is contained in:
parent
93c12fad28
commit
c3c7b33351
|
@ -51,10 +51,9 @@ from zerver.models import (
|
||||||
Subscription,
|
Subscription,
|
||||||
UserProfile,
|
UserProfile,
|
||||||
)
|
)
|
||||||
|
|
||||||
from zilencer.models import get_remote_server_by_uuid
|
from zilencer.models import get_remote_server_by_uuid
|
||||||
from zerver.decorator import do_two_factor_login
|
from zerver.decorator import do_two_factor_login
|
||||||
|
from zerver.tornado.event_queue import clear_client_event_queues_for_testing
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
import mock
|
import mock
|
||||||
|
@ -91,6 +90,11 @@ class ZulipTestCase(TestCase):
|
||||||
# Ensure that the test system just shows us diffs
|
# Ensure that the test system just shows us diffs
|
||||||
maxDiff = None # type: Optional[int]
|
maxDiff = None # type: Optional[int]
|
||||||
|
|
||||||
|
def tearDown(self) -> None:
|
||||||
|
super().tearDown()
|
||||||
|
# Important: we need to clear event queues to avoid leaking data to future tests.
|
||||||
|
clear_client_event_queues_for_testing()
|
||||||
|
|
||||||
'''
|
'''
|
||||||
WRAPPER_COMMENT:
|
WRAPPER_COMMENT:
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ from zerver.lib.test_classes import ZulipTestCase
|
||||||
from zerver.lib.test_helpers import POSTRequestMock
|
from zerver.lib.test_helpers import POSTRequestMock
|
||||||
from zerver.models import Recipient, Stream, Subscription, UserProfile, get_stream
|
from zerver.models import Recipient, Stream, Subscription, UserProfile, get_stream
|
||||||
from zerver.tornado.event_queue import maybe_enqueue_notifications, \
|
from zerver.tornado.event_queue import maybe_enqueue_notifications, \
|
||||||
allocate_client_descriptor, process_message_event, clear_client_event_queues_for_testing, \
|
allocate_client_descriptor, process_message_event, \
|
||||||
get_client_descriptor, missedmessage_hook
|
get_client_descriptor, missedmessage_hook
|
||||||
from zerver.tornado.views import get_events
|
from zerver.tornado.views import get_events
|
||||||
|
|
||||||
|
@ -139,8 +139,6 @@ class MissedMessageNotificationsTest(ZulipTestCase):
|
||||||
|
|
||||||
self.unsubscribe(hamlet, stream_name)
|
self.unsubscribe(hamlet, stream_name)
|
||||||
|
|
||||||
clear_client_event_queues_for_testing()
|
|
||||||
|
|
||||||
queue_data = dict(
|
queue_data = dict(
|
||||||
all_public_streams=True,
|
all_public_streams=True,
|
||||||
apply_markdown=True,
|
apply_markdown=True,
|
||||||
|
|
|
@ -160,11 +160,6 @@ class LogEventsTest(ZulipTestCase):
|
||||||
|
|
||||||
|
|
||||||
class EventsEndpointTest(ZulipTestCase):
|
class EventsEndpointTest(ZulipTestCase):
|
||||||
def tearDown(self) -> None:
|
|
||||||
super().tearDown()
|
|
||||||
# Important: we need to clear event queues to avoid leaking data to future tests.
|
|
||||||
clear_client_event_queues_for_testing()
|
|
||||||
|
|
||||||
def test_events_register_endpoint(self) -> None:
|
def test_events_register_endpoint(self) -> None:
|
||||||
|
|
||||||
# This test is intended to get minimal coverage on the
|
# This test is intended to get minimal coverage on the
|
||||||
|
@ -270,11 +265,6 @@ class EventsEndpointTest(ZulipTestCase):
|
||||||
self.assert_json_success(result)
|
self.assert_json_success(result)
|
||||||
|
|
||||||
class GetEventsTest(ZulipTestCase):
|
class GetEventsTest(ZulipTestCase):
|
||||||
def tearDown(self) -> None:
|
|
||||||
super().tearDown()
|
|
||||||
# Important: we need to clear event queues to avoid leaking data to future tests.
|
|
||||||
clear_client_event_queues_for_testing()
|
|
||||||
|
|
||||||
def tornado_call(self, view_func: Callable[[HttpRequest, UserProfile], HttpResponse],
|
def tornado_call(self, view_func: Callable[[HttpRequest, UserProfile], HttpResponse],
|
||||||
user_profile: UserProfile,
|
user_profile: UserProfile,
|
||||||
post_data: Dict[str, Any]) -> HttpResponse:
|
post_data: Dict[str, Any]) -> HttpResponse:
|
||||||
|
@ -458,11 +448,6 @@ class GetEventsTest(ZulipTestCase):
|
||||||
self.assertEqual(message["avatar_url"], None)
|
self.assertEqual(message["avatar_url"], None)
|
||||||
|
|
||||||
class EventsRegisterTest(ZulipTestCase):
|
class EventsRegisterTest(ZulipTestCase):
|
||||||
def tearDown(self) -> None:
|
|
||||||
super().tearDown()
|
|
||||||
# Important: we need to clear event queues to avoid leaking data to future tests.
|
|
||||||
clear_client_event_queues_for_testing()
|
|
||||||
|
|
||||||
def setUp(self) -> None:
|
def setUp(self) -> None:
|
||||||
super().setUp()
|
super().setUp()
|
||||||
self.user_profile = self.example_user('hamlet')
|
self.user_profile = self.example_user('hamlet')
|
||||||
|
@ -487,7 +472,7 @@ class EventsRegisterTest(ZulipTestCase):
|
||||||
'''
|
'''
|
||||||
Make sure we have a clean slate of client descriptors for these tests.
|
Make sure we have a clean slate of client descriptors for these tests.
|
||||||
If we don't do this, then certain failures will only manifest when you
|
If we don't do this, then certain failures will only manifest when you
|
||||||
run multiple tests.
|
run multiple tests within a single test function.
|
||||||
'''
|
'''
|
||||||
clear_client_event_queues_for_testing()
|
clear_client_event_queues_for_testing()
|
||||||
|
|
||||||
|
@ -2755,11 +2740,6 @@ class EventQueueTest(TestCase):
|
||||||
"timestamp": "1"}])
|
"timestamp": "1"}])
|
||||||
|
|
||||||
class ClientDescriptorsTest(ZulipTestCase):
|
class ClientDescriptorsTest(ZulipTestCase):
|
||||||
def tearDown(self) -> None:
|
|
||||||
super().tearDown()
|
|
||||||
# Important: we need to clear event queues to avoid leaking data to future tests.
|
|
||||||
clear_client_event_queues_for_testing()
|
|
||||||
|
|
||||||
def test_get_client_info_for_all_public_streams(self) -> None:
|
def test_get_client_info_for_all_public_streams(self) -> None:
|
||||||
hamlet = self.example_user('hamlet')
|
hamlet = self.example_user('hamlet')
|
||||||
realm = hamlet.realm
|
realm = hamlet.realm
|
||||||
|
|
|
@ -50,8 +50,6 @@ class TornadoWebTestCase(AsyncHTTPTestCase, ZulipTestCase):
|
||||||
def tearDown(self) -> None:
|
def tearDown(self) -> None:
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
self.session_cookie = None # type: Optional[Dict[str, str]]
|
self.session_cookie = None # type: Optional[Dict[str, str]]
|
||||||
# Important: we need to clear event queues to avoid leaking data to future tests.
|
|
||||||
event_queue.clear_client_event_queues_for_testing()
|
|
||||||
|
|
||||||
@override_settings(DEBUG=False)
|
@override_settings(DEBUG=False)
|
||||||
def get_app(self) -> Application:
|
def get_app(self) -> Application:
|
||||||
|
@ -143,7 +141,6 @@ class EventsTestCase(TornadoWebTestCase):
|
||||||
self.assertEqual(data['result'], 'success')
|
self.assertEqual(data['result'], 'success')
|
||||||
|
|
||||||
class WebSocketBaseTestCase(AsyncHTTPTestCase, ZulipTestCase):
|
class WebSocketBaseTestCase(AsyncHTTPTestCase, ZulipTestCase):
|
||||||
|
|
||||||
def setUp(self) -> None:
|
def setUp(self) -> None:
|
||||||
settings.RUNNING_INSIDE_TORNADO = True
|
settings.RUNNING_INSIDE_TORNADO = True
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
@ -151,8 +148,6 @@ class WebSocketBaseTestCase(AsyncHTTPTestCase, ZulipTestCase):
|
||||||
def tearDown(self) -> None:
|
def tearDown(self) -> None:
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
settings.RUNNING_INSIDE_TORNADO = False
|
settings.RUNNING_INSIDE_TORNADO = False
|
||||||
# Important: we need to clear event queues to avoid leaking data to future tests.
|
|
||||||
event_queue.clear_client_event_queues_for_testing()
|
|
||||||
|
|
||||||
@gen.coroutine
|
@gen.coroutine
|
||||||
def ws_connect(self, path: str, cookie_header: str,
|
def ws_connect(self, path: str, cookie_header: str,
|
||||||
|
|
Loading…
Reference in New Issue