diff options
author | Erik Johnston <erik@matrix.org> | 2024-07-30 14:17:51 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2024-07-30 14:17:51 +0100 |
commit | b1125d0ec15442040d3495d4bdbfb2d2f5595d79 (patch) | |
tree | ebc70da436513b4d0c56be50dc51a98fe34eb4f6 /tests/rest/client/test_sync.py | |
parent | Don't set the initial flag (diff) | |
parent | Bump ruff from 0.5.4 to 0.5.5 (#17494) (diff) | |
download | synapse-b1125d0ec15442040d3495d4bdbfb2d2f5595d79.tar.xz |
Merge remote-tracking branch 'origin/develop' into erikj/ss_hacks
Diffstat (limited to 'tests/rest/client/test_sync.py')
-rw-r--r-- | tests/rest/client/test_sync.py | 168 |
1 files changed, 71 insertions, 97 deletions
diff --git a/tests/rest/client/test_sync.py b/tests/rest/client/test_sync.py index 7c961cf939..a97660e2f2 100644 --- a/tests/rest/client/test_sync.py +++ b/tests/rest/client/test_sync.py @@ -4457,7 +4457,7 @@ class SlidingSyncTestCase(SlidingSyncBase): # `world_readable` but currently we don't support this. self.assertIsNone(response_body["rooms"].get(room_id1), response_body["rooms"]) - def test_incremental_sync_incremental_state(self) -> None: + def test_rooms_required_state_incremental_sync_LIVE(self) -> None: """Test that we only get state updates in incremental sync for rooms we've already seen (LIVE). """ @@ -4512,6 +4512,7 @@ class SlidingSyncTestCase(SlidingSyncBase): self.storage_controllers.state.get_current_state(room_id1) ) + self.assertNotIn("initial", response_body["rooms"][room_id1]) self._assertRequiredStateIncludes( response_body["rooms"][room_id1]["required_state"], { @@ -4520,78 +4521,8 @@ class SlidingSyncTestCase(SlidingSyncBase): exact=True, ) - def test_incremental_sync_full_state_new_room(self) -> None: - """Test that we get all state in incremental sync for rooms that - we haven't seen before. - """ - - user1_id = self.register_user("user1", "pass") - user1_tok = self.login(user1_id, "pass") - user2_id = self.register_user("user2", "pass") - user2_tok = self.login(user2_id, "pass") - - room_id1 = self.helper.create_room_as(user2_id, tok=user2_tok) - self.helper.join(room_id1, user1_id, tok=user1_tok) - - room_id2 = self.helper.create_room_as(user2_id, tok=user2_tok) - self.helper.join(room_id2, user1_id, tok=user1_tok) - - # Make the Sliding Sync request, we'll only receive room_id2 - sync_body = { - "lists": { - "foo-list": { - "ranges": [[0, 0]], - "required_state": [ - [EventTypes.Create, ""], - [EventTypes.RoomHistoryVisibility, ""], - # This one doesn't exist in the room - [EventTypes.Name, ""], - ], - "timeline_limit": 0, - } - } - } - - response_body, from_token = self.do_sync(sync_body, tok=user1_tok) - - state_map = self.get_success( - self.storage_controllers.state.get_current_state(room_id2) - ) - - self._assertRequiredStateIncludes( - response_body["rooms"][room_id2]["required_state"], - { - state_map[(EventTypes.Create, "")], - state_map[(EventTypes.RoomHistoryVisibility, "")], - }, - exact=True, - ) - self.assertNotIn(room_id1, response_body["rooms"]) - - # Send a state event in room 1 - self.helper.send_state( - room_id1, EventTypes.Name, body={"name": "foo"}, tok=user2_tok - ) - - # We should get room_id1 down sync, with the full state. - response_body, _ = self.do_sync(sync_body, since=from_token, tok=user1_tok) - - state_map = self.get_success( - self.storage_controllers.state.get_current_state(room_id1) - ) - - self._assertRequiredStateIncludes( - response_body["rooms"][room_id1]["required_state"], - { - state_map[(EventTypes.Create, "")], - state_map[(EventTypes.RoomHistoryVisibility, "")], - state_map[(EventTypes.Name, "")], - }, - exact=True, - ) - @parameterized.expand([(False,), (True,)]) - def test_incremental_sync_full_state_previously(self, limited: bool) -> None: + def test_rooms_timeline_incremental_sync_PREVIOUSLY(self, limited: bool) -> None: """ Test getting room data where we have previously sent down the room, but we missed sending down some timeline events previously and so its status @@ -4615,12 +4546,7 @@ class SlidingSyncTestCase(SlidingSyncBase): "lists": { "foo-list": { "ranges": [[0, 0]], - "required_state": [ - [EventTypes.Create, ""], - [EventTypes.RoomHistoryVisibility, ""], - # This one doesn't exist in the room - [EventTypes.Name, ""], - ], + "required_state": [], "timeline_limit": timeline_limit, } }, @@ -4699,6 +4625,7 @@ class SlidingSyncTestCase(SlidingSyncBase): self.assertCountEqual( response_body["rooms"].keys(), {room_id1}, response_body["rooms"] ) + self.assertNotIn("initial", response_body["rooms"][room_id1]) self.assertEqual( [ev["event_id"] for ev in response_body["rooms"][room_id1]["timeline"]], @@ -4707,7 +4634,7 @@ class SlidingSyncTestCase(SlidingSyncBase): self.assertEqual(response_body["rooms"][room_id1]["limited"], limited) self.assertEqual(response_body["rooms"][room_id1].get("required_state"), None) - def test_incremental_sync_full_state_previously_state(self) -> None: + def test_rooms_required_state_incremental_sync_PREVIOUSLY(self) -> None: """ Test getting room data where we have previously sent down the room, but we missed sending down some state previously and so its status is @@ -4722,7 +4649,6 @@ class SlidingSyncTestCase(SlidingSyncBase): self.helper.send(room_id1, "msg", tok=user1_tok) - timeline_limit = 5 conn_id = "conn_id" sync_body = { "lists": { @@ -4734,7 +4660,7 @@ class SlidingSyncTestCase(SlidingSyncBase): # This one doesn't exist in the room [EventTypes.Name, ""], ], - "timeline_limit": timeline_limit, + "timeline_limit": 0, } }, "conn_id": "conn_id", @@ -4746,7 +4672,7 @@ class SlidingSyncTestCase(SlidingSyncBase): response_body["rooms"].keys(), {room_id1}, response_body["rooms"] ) - # We now send down some state in room1 (depending on the test param). + # We now send down some state in room1 resp = self.helper.send_state( room_id1, EventTypes.Name, {"name": "foo"}, tok=user1_tok ) @@ -4807,6 +4733,7 @@ class SlidingSyncTestCase(SlidingSyncBase): self.assertCountEqual( response_body["rooms"].keys(), {room_id1}, response_body["rooms"] ) + self.assertNotIn("initial", response_body["rooms"][room_id1]) # We should only see the name change. self.assertEqual( @@ -4817,9 +4744,9 @@ class SlidingSyncTestCase(SlidingSyncBase): [name_change_id], ) - def test_incremental_sync_full_state_never(self) -> None: + def test_rooms_required_state_incremental_sync_NEVER(self) -> None: """ - Test getting room data where we have not previously sent down the room + Test getting `required_state` where we have NEVER sent down the room before """ user1_id = self.register_user("user1", "pass") @@ -4857,8 +4784,7 @@ class SlidingSyncTestCase(SlidingSyncBase): # We now send another event to room1, so we should send down the full # room. - resp = self.helper.send(room_id1, "msg2", tok=user1_tok) - latest_message_event = resp["event_id"] + self.helper.send(room_id1, "msg2", tok=user1_tok) # This sync should contain the messages from room1 not yet sent down. response_body, _ = self.do_sync(sync_body, since=from_token, tok=user1_tok) @@ -4867,11 +4793,6 @@ class SlidingSyncTestCase(SlidingSyncBase): response_body["rooms"].keys(), {room_id1}, response_body["rooms"] ) - self.assertEqual( - [ev["event_id"] for ev in response_body["rooms"][room_id1]["timeline"]], - [latest_message_event], - ) - self.assertEqual(response_body["rooms"][room_id1]["limited"], True) self.assertEqual(response_body["rooms"][room_id1]["initial"], True) state_map = self.get_success( @@ -4887,6 +4808,61 @@ class SlidingSyncTestCase(SlidingSyncBase): exact=True, ) + def test_rooms_timeline_incremental_sync_NEVER(self) -> None: + """ + Test getting timeline room data where we have NEVER sent down the room + before + """ + + user1_id = self.register_user("user1", "pass") + user1_tok = self.login(user1_id, "pass") + + room_id1 = self.helper.create_room_as(user1_id, tok=user1_tok) + room_id2 = self.helper.create_room_as(user1_id, tok=user1_tok) + + sync_body = { + "lists": { + "foo-list": { + "ranges": [[0, 0]], + "required_state": [], + "timeline_limit": 5, + } + }, + } + + expected_events = [] + for _ in range(4): + resp = self.helper.send(room_id1, "msg", tok=user1_tok) + expected_events.append(resp["event_id"]) + + # A message happens in the other room, so room1 won't get sent down. + self.helper.send(room_id2, "msg", tok=user1_tok) + + # Only the second room gets sent down sync. + response_body, from_token = self.do_sync(sync_body, tok=user1_tok) + + self.assertCountEqual( + response_body["rooms"].keys(), {room_id2}, response_body["rooms"] + ) + + # We now send another event to room1 so it comes down sync + resp = self.helper.send(room_id1, "msg2", tok=user1_tok) + expected_events.append(resp["event_id"]) + + # This sync should contain the messages from room1 not yet sent down. + response_body, _ = self.do_sync(sync_body, since=from_token, tok=user1_tok) + + self.assertCountEqual( + response_body["rooms"].keys(), {room_id1}, response_body["rooms"] + ) + + self.assertEqual( + [ev["event_id"] for ev in response_body["rooms"][room_id1]["timeline"]], + expected_events, + ) + self.assertEqual(response_body["rooms"][room_id1]["limited"], True) + self.assertEqual(response_body["rooms"][room_id1]["initial"], True) + def test_rooms_with_no_updates_do_not_come_down_incremental_sync(self) -> None: """ Test that rooms with no updates are returned in subsequent incremental @@ -4908,18 +4884,16 @@ class SlidingSyncTestCase(SlidingSyncBase): } } - _, after_room_token = self.do_sync(sync_body, tok=user1_tok) + _, from_token = self.do_sync(sync_body, tok=user1_tok) - # Make the Sliding Sync request - response_body, _ = self.do_sync( - sync_body, since=after_room_token, tok=user1_tok - ) + # Make the incremental Sliding Sync request + response_body, _ = self.do_sync(sync_body, since=from_token, tok=user1_tok) # Nothing has happened in the room, so the room should not come down # /sync. self.assertIsNone(response_body["rooms"].get(room_id1)) - def test_empty_room_comes_down_sync(self) -> None: + def test_empty_initial_room_comes_down_sync(self) -> None: """ Test that rooms come down /sync even with empty required state and timeline limit in initial sync. |