summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorEric Eastwood <eric.eastwood@beta.gouv.fr>2024-05-16 11:54:46 -0500
committerGitHub <noreply@github.com>2024-05-16 11:54:46 -0500
commit28a948f04f1e04cbcbd68c53a78aa2ada3a791a1 (patch)
tree6eca39530211b38b03e803ed8c84039b9d7fcaa1 /tests
parentRoute `/make_knock` and `/send_knock` to workers in Complement docker image (... (diff)
downloadsynapse-28a948f04f1e04cbcbd68c53a78aa2ada3a791a1.tar.xz
Removed `request_key` from the `SyncConfig` (moved outside as its own function parameter) (#17201)
Removed `request_key` from the `SyncConfig` (moved outside as its own function parameter) so it doesn't have to flow into `_generate_sync_entry_for_xxx` methods. This way we can separate the concerns of caching from generating the response and reuse the `_generate_sync_entry_for_xxx` functions as we see fit. Plus caching doesn't really have anything to do with the config of sync.

Split from https://github.com/element-hq/synapse/pull/17167

Spawning from https://github.com/element-hq/synapse/pull/17167#discussion_r1601497279
Diffstat (limited to 'tests')
-rw-r--r--tests/events/test_presence_router.py17
-rw-r--r--tests/handlers/test_sync.py47
2 files changed, 54 insertions, 10 deletions
diff --git a/tests/events/test_presence_router.py b/tests/events/test_presence_router.py
index aa67afa695..e48983ddfe 100644
--- a/tests/events/test_presence_router.py
+++ b/tests/events/test_presence_router.py
@@ -36,7 +36,7 @@ from synapse.server import HomeServer
 from synapse.types import JsonDict, StreamToken, create_requester
 from synapse.util import Clock
 
-from tests.handlers.test_sync import SyncVersion, generate_sync_config
+from tests.handlers.test_sync import SyncRequestKey, SyncVersion, generate_sync_config
 from tests.unittest import (
     FederatingHomeserverTestCase,
     HomeserverTestCase,
@@ -498,6 +498,15 @@ def send_presence_update(
     return channel.json_body
 
 
+_request_key = 0
+
+
+def generate_request_key() -> SyncRequestKey:
+    global _request_key
+    _request_key += 1
+    return ("request_key", _request_key)
+
+
 def sync_presence(
     testcase: HomeserverTestCase,
     user_id: str,
@@ -521,7 +530,11 @@ def sync_presence(
     sync_config = generate_sync_config(requester.user.to_string())
     sync_result = testcase.get_success(
         testcase.hs.get_sync_handler().wait_for_sync_for_user(
-            requester, sync_config, SyncVersion.SYNC_V2, since_token
+            requester,
+            sync_config,
+            SyncVersion.SYNC_V2,
+            generate_request_key(),
+            since_token,
         )
     )
 
diff --git a/tests/handlers/test_sync.py b/tests/handlers/test_sync.py
index 0299113b95..02371ce724 100644
--- a/tests/handlers/test_sync.py
+++ b/tests/handlers/test_sync.py
@@ -31,7 +31,7 @@ from synapse.api.room_versions import RoomVersion, RoomVersions
 from synapse.events import EventBase
 from synapse.events.snapshot import EventContext
 from synapse.federation.federation_base import event_from_pdu_json
-from synapse.handlers.sync import SyncConfig, SyncResult, SyncVersion
+from synapse.handlers.sync import SyncConfig, SyncRequestKey, SyncResult, SyncVersion
 from synapse.rest import admin
 from synapse.rest.client import knock, login, room
 from synapse.server import HomeServer
@@ -41,6 +41,14 @@ from synapse.util import Clock
 import tests.unittest
 import tests.utils
 
+_request_key = 0
+
+
+def generate_request_key() -> SyncRequestKey:
+    global _request_key
+    _request_key += 1
+    return ("request_key", _request_key)
+
 
 class SyncTestCase(tests.unittest.HomeserverTestCase):
     """Tests Sync Handler."""
@@ -77,6 +85,7 @@ class SyncTestCase(tests.unittest.HomeserverTestCase):
                 requester,
                 sync_config,
                 sync_version=SyncVersion.SYNC_V2,
+                request_key=generate_request_key(),
             )
         )
 
@@ -87,6 +96,7 @@ class SyncTestCase(tests.unittest.HomeserverTestCase):
                 requester,
                 sync_config,
                 sync_version=SyncVersion.SYNC_V2,
+                request_key=generate_request_key(),
             ),
             ResourceLimitError,
         )
@@ -102,6 +112,7 @@ class SyncTestCase(tests.unittest.HomeserverTestCase):
                 requester,
                 sync_config,
                 sync_version=SyncVersion.SYNC_V2,
+                request_key=generate_request_key(),
             ),
             ResourceLimitError,
         )
@@ -124,6 +135,7 @@ class SyncTestCase(tests.unittest.HomeserverTestCase):
                 requester,
                 sync_config=generate_sync_config(user, device_id="dev"),
                 sync_version=SyncVersion.SYNC_V2,
+                request_key=generate_request_key(),
             )
         )
 
@@ -157,6 +169,7 @@ class SyncTestCase(tests.unittest.HomeserverTestCase):
                 requester,
                 sync_config=generate_sync_config(user),
                 sync_version=SyncVersion.SYNC_V2,
+                request_key=generate_request_key(),
             )
         )
         self.assertIn(joined_room, [r.room_id for r in result.joined])
@@ -169,6 +182,7 @@ class SyncTestCase(tests.unittest.HomeserverTestCase):
                 requester,
                 sync_config=generate_sync_config(user, device_id="dev"),
                 sync_version=SyncVersion.SYNC_V2,
+                request_key=generate_request_key(),
                 since_token=initial_result.next_batch,
             )
         )
@@ -200,6 +214,7 @@ class SyncTestCase(tests.unittest.HomeserverTestCase):
                 requester,
                 sync_config=generate_sync_config(user),
                 sync_version=SyncVersion.SYNC_V2,
+                request_key=generate_request_key(),
             )
         )
         self.assertNotIn(joined_room, [r.room_id for r in result.joined])
@@ -212,6 +227,7 @@ class SyncTestCase(tests.unittest.HomeserverTestCase):
                 requester,
                 sync_config=generate_sync_config(user, device_id="dev"),
                 sync_version=SyncVersion.SYNC_V2,
+                request_key=generate_request_key(),
                 since_token=initial_result.next_batch,
             )
         )
@@ -254,6 +270,7 @@ class SyncTestCase(tests.unittest.HomeserverTestCase):
                 create_requester(owner),
                 generate_sync_config(owner),
                 sync_version=SyncVersion.SYNC_V2,
+                request_key=generate_request_key(),
             )
         )
         self.assertEqual(len(alice_sync_result.joined), 1)
@@ -277,6 +294,7 @@ class SyncTestCase(tests.unittest.HomeserverTestCase):
                 eve_requester,
                 eve_sync_config,
                 sync_version=SyncVersion.SYNC_V2,
+                request_key=generate_request_key(),
             )
         )
 
@@ -295,6 +313,7 @@ class SyncTestCase(tests.unittest.HomeserverTestCase):
                 eve_requester,
                 eve_sync_config,
                 sync_version=SyncVersion.SYNC_V2,
+                request_key=generate_request_key(),
                 since_token=eve_sync_after_ban.next_batch,
             )
         )
@@ -307,6 +326,7 @@ class SyncTestCase(tests.unittest.HomeserverTestCase):
                 eve_requester,
                 eve_sync_config,
                 sync_version=SyncVersion.SYNC_V2,
+                request_key=generate_request_key(),
                 since_token=None,
             )
         )
@@ -341,6 +361,7 @@ class SyncTestCase(tests.unittest.HomeserverTestCase):
                 alice_requester,
                 generate_sync_config(alice),
                 sync_version=SyncVersion.SYNC_V2,
+                request_key=generate_request_key(),
             )
         )
         last_room_creation_event_id = (
@@ -369,6 +390,7 @@ class SyncTestCase(tests.unittest.HomeserverTestCase):
                     ),
                 ),
                 sync_version=SyncVersion.SYNC_V2,
+                request_key=generate_request_key(),
                 since_token=initial_sync_result.next_batch,
             )
         )
@@ -414,6 +436,7 @@ class SyncTestCase(tests.unittest.HomeserverTestCase):
                 alice_requester,
                 generate_sync_config(alice),
                 sync_version=SyncVersion.SYNC_V2,
+                request_key=generate_request_key(),
             )
         )
         last_room_creation_event_id = (
@@ -452,6 +475,7 @@ class SyncTestCase(tests.unittest.HomeserverTestCase):
                     ),
                 ),
                 sync_version=SyncVersion.SYNC_V2,
+                request_key=generate_request_key(),
                 since_token=initial_sync_result.next_batch,
             )
         )
@@ -498,6 +522,7 @@ class SyncTestCase(tests.unittest.HomeserverTestCase):
                 alice_requester,
                 generate_sync_config(alice),
                 sync_version=SyncVersion.SYNC_V2,
+                request_key=generate_request_key(),
             )
         )
         last_room_creation_event_id = (
@@ -523,6 +548,7 @@ class SyncTestCase(tests.unittest.HomeserverTestCase):
                     ),
                 ),
                 sync_version=SyncVersion.SYNC_V2,
+                request_key=generate_request_key(),
                 since_token=initial_sync_result.next_batch,
             )
         )
@@ -553,6 +579,7 @@ class SyncTestCase(tests.unittest.HomeserverTestCase):
                     ),
                 ),
                 sync_version=SyncVersion.SYNC_V2,
+                request_key=generate_request_key(),
                 since_token=incremental_sync.next_batch,
             )
         )
@@ -615,6 +642,7 @@ class SyncTestCase(tests.unittest.HomeserverTestCase):
                 alice_requester,
                 generate_sync_config(alice),
                 sync_version=SyncVersion.SYNC_V2,
+                request_key=generate_request_key(),
             )
         )
         last_room_creation_event_id = (
@@ -639,6 +667,7 @@ class SyncTestCase(tests.unittest.HomeserverTestCase):
                     ),
                 ),
                 sync_version=SyncVersion.SYNC_V2,
+                request_key=generate_request_key(),
             )
         )
         room_sync = initial_sync_result.joined[0]
@@ -660,6 +689,7 @@ class SyncTestCase(tests.unittest.HomeserverTestCase):
                 alice_requester,
                 generate_sync_config(alice),
                 sync_version=SyncVersion.SYNC_V2,
+                request_key=generate_request_key(),
                 since_token=initial_sync_result.next_batch,
             )
         )
@@ -713,6 +743,7 @@ class SyncTestCase(tests.unittest.HomeserverTestCase):
                 bob_requester,
                 generate_sync_config(bob),
                 sync_version=SyncVersion.SYNC_V2,
+                request_key=generate_request_key(),
             )
         )
 
@@ -744,6 +775,7 @@ class SyncTestCase(tests.unittest.HomeserverTestCase):
                     bob, filter_collection=FilterCollection(self.hs, filter_dict)
                 ),
                 sync_version=SyncVersion.SYNC_V2,
+                request_key=generate_request_key(),
                 since_token=None if initial_sync else initial_sync_result.next_batch,
             )
         ).archived[0]
@@ -839,6 +871,7 @@ class SyncTestCase(tests.unittest.HomeserverTestCase):
                 create_requester(user),
                 generate_sync_config(user),
                 sync_version=SyncVersion.SYNC_V2,
+                request_key=generate_request_key(),
             )
         )
         event_ids = []
@@ -887,6 +920,7 @@ class SyncTestCase(tests.unittest.HomeserverTestCase):
                 create_requester(user2),
                 generate_sync_config(user2),
                 sync_version=SyncVersion.SYNC_V2,
+                request_key=generate_request_key(),
             )
         )
         priv_event_ids = []
@@ -909,7 +943,10 @@ class SyncTestCase(tests.unittest.HomeserverTestCase):
 
         sync_result: SyncResult = self.get_success(
             self.sync_handler.wait_for_sync_for_user(
-                create_requester(user), generate_sync_config(user)
+                create_requester(user),
+                generate_sync_config(user),
+                sync_version=SyncVersion.SYNC_V2,
+                request_key=generate_request_key(),
             )
         )
 
@@ -923,9 +960,6 @@ class SyncTestCase(tests.unittest.HomeserverTestCase):
         self.fail("No push rules found")
 
 
-_request_key = 0
-
-
 def generate_sync_config(
     user_id: str,
     device_id: Optional[str] = "device_id",
@@ -942,12 +976,9 @@ def generate_sync_config(
     if filter_collection is None:
         filter_collection = Filtering(Mock()).DEFAULT_FILTER_COLLECTION
 
-    global _request_key
-    _request_key += 1
     return SyncConfig(
         user=UserID.from_string(user_id),
         filter_collection=filter_collection,
         is_guest=False,
-        request_key=("request_key", _request_key),
         device_id=device_id,
     )