mirror of
https://github.com/zulip/zulip.git
synced 2025-10-29 11:03:54 +00:00
tornado: Drop WebReloadClientError logic.
The widening of the time between when a process is marked for reload (at Tornado startup) and when it sends reload events makes it unlikely-to-impossible that a single `/` request will span both of them, and thus hit the WebReloadClientError corner case. Remove it, as it is not worth the complication. The bad behaviour it is attempting to prevent (of a reload right after opening `/`) was always still possible -- if the `/` request completed right before Tornado restarted -- so it is not clear that it was ever worth the complication.
This commit is contained in:
committed by
Tim Abbott
parent
da6b0b1cc6
commit
0079688c49
@@ -1,5 +1,5 @@
|
||||
import time
|
||||
from typing import Any, Callable, Dict, List, Optional
|
||||
from typing import Any, Callable, Dict, List
|
||||
from unittest import mock
|
||||
from urllib.parse import urlsplit
|
||||
|
||||
@@ -41,12 +41,8 @@ from zerver.tornado.event_queue import (
|
||||
send_web_reload_client_events,
|
||||
)
|
||||
from zerver.tornado.exceptions import BadEventQueueIdError
|
||||
from zerver.tornado.views import get_events, get_events_backend
|
||||
from zerver.views.events_register import (
|
||||
_default_all_public_streams,
|
||||
_default_narrow,
|
||||
events_register_backend,
|
||||
)
|
||||
from zerver.tornado.views import get_events
|
||||
from zerver.views.events_register import _default_all_public_streams, _default_narrow
|
||||
|
||||
|
||||
class EventsEndpointTest(ZulipTestCase):
|
||||
@@ -1113,28 +1109,7 @@ class ClientDescriptorsTest(ZulipTestCase):
|
||||
)
|
||||
|
||||
|
||||
class WebReloadClientsTest(ZulipTestCase):
|
||||
def tornado_call(
|
||||
self,
|
||||
view_func: Callable[[HttpRequest, UserProfile], HttpResponse],
|
||||
user_profile: UserProfile,
|
||||
post_data: Dict[str, Any],
|
||||
client_name: Optional[str] = None,
|
||||
user_agent: Optional[str] = None,
|
||||
) -> HttpResponse:
|
||||
meta_data: Optional[Dict[str, Any]] = None
|
||||
if user_agent is not None:
|
||||
meta_data = {"HTTP_USER_AGENT": user_agent}
|
||||
|
||||
request = HostRequestMock(
|
||||
post_data,
|
||||
user_profile,
|
||||
client_name=client_name,
|
||||
tornado_handler=dummy_handler,
|
||||
meta_data=meta_data,
|
||||
)
|
||||
return view_func(request, user_profile)
|
||||
|
||||
class ReloadWebClientsTest(ZulipTestCase):
|
||||
def test_web_reload_clients(self) -> None:
|
||||
hamlet = self.example_user("hamlet")
|
||||
realm = hamlet.realm
|
||||
@@ -1172,79 +1147,6 @@ class WebReloadClientsTest(ZulipTestCase):
|
||||
),
|
||||
)
|
||||
|
||||
def test_web_reload_client_event_recursive_call_logic(self) -> None:
|
||||
# This is a test for a subtle corner case; see the comments
|
||||
# around WebReloadClientError for details.
|
||||
hamlet = self.example_user("hamlet")
|
||||
realm = hamlet.realm
|
||||
|
||||
# Set up an empty event queue
|
||||
clear_client_event_queues_for_testing()
|
||||
|
||||
queue_data = dict(
|
||||
all_public_streams=False,
|
||||
apply_markdown=True,
|
||||
client_gravatar=True,
|
||||
client_type_name="website",
|
||||
event_types=None,
|
||||
last_connection_time=time.time(),
|
||||
queue_timeout=0,
|
||||
realm_id=realm.id,
|
||||
user_profile_id=hamlet.id,
|
||||
)
|
||||
client = allocate_client_descriptor(queue_data)
|
||||
|
||||
# Add a reload event to it.
|
||||
send_web_reload_client_events()
|
||||
|
||||
# Make a second queue after the reload events were sent.
|
||||
second_client = allocate_client_descriptor(queue_data)
|
||||
|
||||
# Fetch the reload event just sent above, without removing it
|
||||
# from the queue. We will use this as a mock return value in
|
||||
# get_user_events.
|
||||
reload_event = orjson.loads(
|
||||
self.tornado_call(
|
||||
get_events_backend,
|
||||
hamlet,
|
||||
post_data={
|
||||
"queue_id": client.event_queue.id,
|
||||
"last_event_id": -1,
|
||||
"dont_block": "true",
|
||||
"user_profile_id": hamlet.id,
|
||||
"secret": settings.SHARED_SECRET,
|
||||
"client": "internal",
|
||||
},
|
||||
client_name="internal",
|
||||
).content
|
||||
)["events"]
|
||||
|
||||
# Now the tricky part: We call events_register_backend,
|
||||
# arranging it so that the first `get_user_events` call
|
||||
# returns our reload event (triggering the recursive
|
||||
# behavior), but the second (with a new queue) returns no
|
||||
# events.
|
||||
#
|
||||
# Because get_user_events always returns [] in tests, we need
|
||||
# to mock its return value as well; in an ideal world, we
|
||||
# would only need to mock client / second_client.
|
||||
with mock.patch(
|
||||
"zerver.lib.events.request_event_queue",
|
||||
side_effect=[client.event_queue.id, second_client.event_queue.id],
|
||||
), mock.patch("zerver.lib.events.get_user_events", side_effect=[reload_event, []]):
|
||||
self.tornado_call(
|
||||
events_register_backend,
|
||||
hamlet,
|
||||
{
|
||||
"queue_id": client.event_queue.id,
|
||||
"user_client": "website",
|
||||
"last_event_id": -1,
|
||||
"dont_block": orjson.dumps(True).decode(),
|
||||
},
|
||||
client_name="website",
|
||||
user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
|
||||
)
|
||||
|
||||
|
||||
class FetchQueriesTest(ZulipTestCase):
|
||||
def test_queries(self) -> None:
|
||||
|
||||
Reference in New Issue
Block a user