tornado: Stop collapsing "restart" events via virtual events.

Collapsing was done incorrectly, as 65c400e06d added `zulip_version`
and `zulip_feature_level`, but did not update the virtual event logic
to copy those new values into the virtual event.

However, it is unlikely that a server will be upgraded multiple times
in quick enough succession for this to ever be relevant.  Remove the
logic, which is additional complication for little or no gain.
This commit is contained in:
Alex Vandiver 2024-02-09 20:29:01 +00:00 committed by Tim Abbott
parent 52a80e1d78
commit a6287faea4
3 changed files with 24 additions and 32 deletions

View File

@ -1312,9 +1312,7 @@ class EventQueueTest(ZulipTestCase):
umfe(timestamp=1, messages=[101]),
umfe(timestamp=2, messages=[201, 202]),
dict(type="unknown"),
dict(type="restart", server_generation="1"),
umfe(timestamp=3, messages=[301, 302, 303]),
dict(type="restart", server_generation="2"),
umfe(timestamp=4, messages=[401, 402, 403, 404]),
]
@ -1327,9 +1325,8 @@ class EventQueueTest(ZulipTestCase):
queue.contents(),
[
dict(id=2, type="unknown"),
dict(id=5, type="restart", server_generation="2"),
dict(
id=6,
id=4,
type="update_message_flags",
operation="add",
flag="read",
@ -1353,9 +1350,8 @@ class EventQueueTest(ZulipTestCase):
queue.contents(),
[
dict(id=2, type="unknown"),
dict(id=5, type="restart", server_generation="2"),
dict(
id=6,
id=4,
type="update_message_flags",
operation="add",
flag="read",
@ -1364,7 +1360,7 @@ class EventQueueTest(ZulipTestCase):
messages=[101, 201, 202, 301, 302, 303, 401, 402, 403, 404],
),
dict(
id=7,
id=5,
type="update_message_flags",
operation="add",
flag="read",
@ -1465,23 +1461,28 @@ class EventQueueTest(ZulipTestCase):
of the same form. See the code in
EventQueue.push for more context.
"""
event = dict(
id=0,
type="update_message_flags",
operation="add",
flag="read",
all=False,
timestamp=1,
messages=[101],
)
client = self.get_client_descriptor()
queue = client.event_queue
queue.push({"type": "restart", "server_generation": 1, "timestamp": "1"})
# Verify the server_generation event is stored as a virtual event
self.assertEqual(
queue.virtual_events,
{"restart": {"id": 0, "type": "restart", "server_generation": 1, "timestamp": "1"}},
)
queue.push(event)
# Verify the event is stored as a virtual event
self.assertEqual(queue.virtual_events, {"flags/add/read": event})
# And we can reconstruct newest_pruned_id etc.
self.verify_to_dict_end_to_end(client)
queue.push({"type": "unknown", "timestamp": "1"})
self.assertEqual(list(queue.queue), [{"id": 1, "type": "unknown", "timestamp": "1"}])
self.assertEqual(
queue.virtual_events,
{"restart": {"id": 0, "type": "restart", "server_generation": 1, "timestamp": "1"}},
)
self.assertEqual(queue.virtual_events, {"flags/add/read": event})
# And we can still reconstruct newest_pruned_id etc. correctly
self.verify_to_dict_end_to_end(client)
@ -1489,7 +1490,7 @@ class EventQueueTest(ZulipTestCase):
self.assertEqual(
queue.contents(),
[
{"id": 0, "type": "restart", "server_generation": 1, "timestamp": "1"},
event,
{"id": 1, "type": "unknown", "timestamp": "1"},
],
)

View File

@ -1143,13 +1143,8 @@ class RestartEventsTest(ZulipTestCase):
send_restart_events(immediate=True)
# For now we only verify that a virtual event
# gets added to the client's event_queue. We
# may decide to write a deeper test in the future
# that exercises the finish_handler.
virtual_events = client.event_queue.virtual_events
self.assert_length(virtual_events, 1)
restart_event = virtual_events["restart"]
self.assert_length(client.event_queue.queue, 1)
restart_event = client.event_queue.queue[0]
check_restart_event("restart_event", restart_event)
self.assertEqual(

View File

@ -359,9 +359,8 @@ class EventQueue:
event["id"] = self.next_event_id
self.next_event_id += 1
full_event_type = compute_full_event_type(event)
if full_event_type == "restart" or (
full_event_type.startswith("flags/")
and not full_event_type.startswith("flags/remove/read")
if full_event_type.startswith("flags/") and not full_event_type.startswith(
"flags/remove/read"
):
# virtual_events are an optimization that allows certain
# simple events, such as update_message_flags events that
@ -384,13 +383,10 @@ class EventQueue:
# Update the virtual event with the values from the event
virtual_event = self.virtual_events[full_event_type]
virtual_event["id"] = event["id"]
virtual_event["messages"] += event["messages"]
if "timestamp" in event:
virtual_event["timestamp"] = event["timestamp"]
if full_event_type == "restart":
virtual_event["server_generation"] = event["server_generation"]
elif full_event_type.startswith("flags/"):
virtual_event["messages"] += event["messages"]
else:
self.queue.append(event)