summary refs log tree commit diff
path: root/tests/handlers
diff options
context:
space:
mode:
authorErik Johnston <erikj@element.io>2024-05-31 16:07:05 +0100
committerGitHub <noreply@github.com>2024-05-31 16:07:05 +0100
commit5c2a837e3cb3eb307f080a7991f464598f43f283 (patch)
tree8f4008b44ae04fd9355d7d64f1b8319a1bbab265 /tests/handlers
parentFix logging errors when receiving invalid User ID for key querys (#17250) (diff)
downloadsynapse-5c2a837e3cb3eb307f080a7991f464598f43f283.tar.xz
Fix bug where typing replication breaks (#17252)
This can happen on restarts of the service, due to old rooms being
pruned.
Diffstat (limited to 'tests/handlers')
-rw-r--r--tests/handlers/test_typing.py53
1 files changed, 52 insertions, 1 deletions
diff --git a/tests/handlers/test_typing.py b/tests/handlers/test_typing.py
index c754083967..9d8960315f 100644
--- a/tests/handlers/test_typing.py
+++ b/tests/handlers/test_typing.py
@@ -32,7 +32,7 @@ from twisted.web.resource import Resource
 from synapse.api.constants import EduTypes
 from synapse.api.errors import AuthError
 from synapse.federation.transport.server import TransportLayerServer
-from synapse.handlers.typing import TypingWriterHandler
+from synapse.handlers.typing import FORGET_TIMEOUT, TypingWriterHandler
 from synapse.http.federation.matrix_federation_agent import MatrixFederationAgent
 from synapse.server import HomeServer
 from synapse.types import JsonDict, Requester, StreamKeyType, UserID, create_requester
@@ -501,3 +501,54 @@ class TypingNotificationsTestCase(unittest.HomeserverTestCase):
                 }
             ],
         )
+
+    def test_prune_typing_replication(self) -> None:
+        """Regression test for `get_all_typing_updates` breaking when we prune
+        old updates
+        """
+        self.room_members = [U_APPLE, U_BANANA]
+
+        instance_name = self.hs.get_instance_name()
+
+        self.get_success(
+            self.handler.started_typing(
+                target_user=U_APPLE,
+                requester=create_requester(U_APPLE),
+                room_id=ROOM_ID,
+                timeout=10000,
+            )
+        )
+
+        rows, _, _ = self.get_success(
+            self.handler.get_all_typing_updates(
+                instance_name=instance_name,
+                last_id=0,
+                current_id=self.handler.get_current_token(),
+                limit=100,
+            )
+        )
+        self.assertEqual(rows, [(1, [ROOM_ID, [U_APPLE.to_string()]])])
+
+        self.reactor.advance(20000)
+
+        rows, _, _ = self.get_success(
+            self.handler.get_all_typing_updates(
+                instance_name=instance_name,
+                last_id=1,
+                current_id=self.handler.get_current_token(),
+                limit=100,
+            )
+        )
+        self.assertEqual(rows, [(2, [ROOM_ID, []])])
+
+        self.reactor.advance(FORGET_TIMEOUT)
+
+        rows, _, _ = self.get_success(
+            self.handler.get_all_typing_updates(
+                instance_name=instance_name,
+                last_id=1,
+                current_id=self.handler.get_current_token(),
+                limit=100,
+            )
+        )
+        self.assertEqual(rows, [])