mirror of https://github.com/zulip/zulip.git
retention: Use a consistent ordering for processing realms.
This is probably a good idea for the production use case, since then there's some consistency of behavior, and if we extend logging, one knows exactly which realms were or were not executed before a logged failure. This fixes the nondeterministic test failures we've been seeing in CI: if you use `-id` in that order_by, it happens consistently.
This commit is contained in:
parent
3e50ed2075
commit
3d1aa98b2e
|
@ -131,7 +131,7 @@ def clean_unused_messages() -> None:
|
||||||
|
|
||||||
|
|
||||||
def archive_messages() -> None:
|
def archive_messages() -> None:
|
||||||
for realm in Realm.objects.filter(message_retention_days__isnull=False):
|
for realm in Realm.objects.filter(message_retention_days__isnull=False).order_by("id"):
|
||||||
move_expired_messages_to_archive(realm)
|
move_expired_messages_to_archive(realm)
|
||||||
move_expired_user_messages_to_archive(realm)
|
move_expired_user_messages_to_archive(realm)
|
||||||
move_expired_attachments_to_archive(realm)
|
move_expired_attachments_to_archive(realm)
|
||||||
|
|
|
@ -263,20 +263,10 @@ class TestRetentionLib(ZulipTestCase):
|
||||||
# Get expired user messages by message ids
|
# Get expired user messages by message ids
|
||||||
expected_user_msgs_ids = list(UserMessage.objects.filter(
|
expected_user_msgs_ids = list(UserMessage.objects.filter(
|
||||||
message_id__in=expected_message_ids).order_by('id').values_list('id', flat=True))
|
message_id__in=expected_message_ids).order_by('id').values_list('id', flat=True))
|
||||||
user_messages = list(UserMessage.objects.select_related(
|
|
||||||
"message").filter(message_id__in=expected_message_ids).order_by('message_id'))
|
|
||||||
|
|
||||||
msgs_qty = Message.objects.count()
|
msgs_qty = Message.objects.count()
|
||||||
archive_messages()
|
archive_messages()
|
||||||
|
|
||||||
# Temporary debugging code while we investigate CI failures
|
|
||||||
for user_message in user_messages: # nocoverage
|
|
||||||
archived = ArchivedUserMessage.objects.filter(
|
|
||||||
message_id=user_message.message_id,
|
|
||||||
user_profile_id=user_message.user_profile_id).exists()
|
|
||||||
if not archived:
|
|
||||||
print("Missing:", user_message, user_message.message_id, flush=True)
|
|
||||||
|
|
||||||
# Compare archived messages and user messages with expired messages
|
# Compare archived messages and user messages with expired messages
|
||||||
self.assertEqual(ArchivedMessage.objects.count(), len(expected_message_ids))
|
self.assertEqual(ArchivedMessage.objects.count(), len(expected_message_ids))
|
||||||
self.assertEqual(ArchivedUserMessage.objects.count(), len(expected_user_msgs_ids))
|
self.assertEqual(ArchivedUserMessage.objects.count(), len(expected_user_msgs_ids))
|
||||||
|
|
Loading…
Reference in New Issue