From 20fbba637542bcb6a3c3abb52d65b790059ef4f0 Mon Sep 17 00:00:00 2001 From: Prakhar Pratyush Date: Thu, 9 May 2024 22:29:39 +0530 Subject: [PATCH] test_realm: Fix a flaky test due to random message populated. The messages populated in the test database are random in nature, so there is a possibility of any number of messages in 'new_stream_announcements_stream' in 'test_merge_streams'. Earlier, the test was assuming of exactly one message in that stream. That would result in a flaky behavior. This commit fixes the flaky behavior. --- zerver/tests/test_realm.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/zerver/tests/test_realm.py b/zerver/tests/test_realm.py index 5d80a526d8..ab6e2b332a 100644 --- a/zerver/tests/test_realm.py +++ b/zerver/tests/test_realm.py @@ -542,6 +542,9 @@ class RealmTest(ZulipTestCase): cordelia = self.example_user("cordelia") new_stream_announcements_stream = realm.get_new_stream_announcements_stream() assert new_stream_announcements_stream is not None + new_stream_announcements_stream_messages_count = Message.objects.filter( + realm_id=realm.id, recipient=new_stream_announcements_stream.recipient + ).count() create_stream_if_needed(realm, "Atlantis") self.subscribe(cordelia, "Atlantis") @@ -558,7 +561,7 @@ class RealmTest(ZulipTestCase): get_stream("Atlantis", realm) stats = merge_streams(realm, denmark, new_stream_announcements_stream) - self.assertEqual(stats, (2, 1, 10)) + self.assertEqual(stats, (2, new_stream_announcements_stream_messages_count, 10)) self.assertIsNone(realm.get_new_stream_announcements_stream()) def test_change_signup_announcements_stream(self) -> None: