message_send: Update do_send_messages codepath to send event on commit.

Earlier, we were using 'send_event' & 'queue_json_publish' in
'do_send_messages' which can lead to a situation where we enqueue
events but the transaction fails at a later stage.

Events should not be sent until we know we're not rolling back.
This commit is contained in:
Prakhar Pratyush
2024-05-15 22:54:37 +05:30
committed by Tim Abbott
parent 27c4e46b30
commit c798d192dc
15 changed files with 473 additions and 270 deletions

View File

@@ -341,16 +341,17 @@ class GetEventsTest(ZulipTestCase):
self.assert_length(events, 0)
local_id = "10.01"
check_send_message(
sender=user_profile,
client=get_client("whatever"),
recipient_type_name="private",
message_to=[recipient_email],
topic_name=None,
message_content="hello",
local_id=local_id,
sender_queue_id=queue_id,
)
with self.captureOnCommitCallbacks(execute=True):
check_send_message(
sender=user_profile,
client=get_client("whatever"),
recipient_type_name="private",
message_to=[recipient_email],
topic_name=None,
message_content="hello",
local_id=local_id,
sender_queue_id=queue_id,
)
result = self.tornado_call(
get_events,
@@ -374,16 +375,17 @@ class GetEventsTest(ZulipTestCase):
last_event_id = events[0]["id"]
local_id = "10.02"
check_send_message(
sender=user_profile,
client=get_client("whatever"),
recipient_type_name="private",
message_to=[recipient_email],
topic_name=None,
message_content="hello",
local_id=local_id,
sender_queue_id=queue_id,
)
with self.captureOnCommitCallbacks(execute=True):
check_send_message(
sender=user_profile,
client=get_client("whatever"),
recipient_type_name="private",
message_to=[recipient_email],
topic_name=None,
message_content="hello",
local_id=local_id,
sender_queue_id=queue_id,
)
result = self.tornado_call(
get_events,