Skip to content

Convert Sliding Sync tests to use higher-level compute_interested_rooms #18399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
May 7, 2025

Conversation

devonh
Copy link
Member

@devonh devonh commented May 5, 2025

Spawning from #18375 (comment),

This updates some sliding sync tests to use a higher level function in order to move test coverage to cover both fallback & new tables. Important when #18375 is merged.

In other words, adjust tests to target compute_interested_room(...) (relevant to both new and fallback path) instead of the lower level get_room_membership_for_user_at_to_token(...) that only applies to the fallback path.

Dev notes

SYNAPSE_TEST_LOG_LEVEL=INFO poetry run trial tests.handlers.test_sliding_sync.ComputeInterestedRoomsTestCase_new
SYNAPSE_TEST_LOG_LEVEL=INFO poetry run trial tests.rest.client.sliding_sync
SYNAPSE_POSTGRES=1 SYNAPSE_POSTGRES_USER=postgres SYNAPSE_TEST_LOG_LEVEL=INFO poetry run trial tests.handlers.test_sliding_sync.ComputeInterestedRoomsTestCase_new.test_display_name_changes_leave_after_token_range

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file. The entry should:
    • Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from EventStore to EventWorkerStore.".
    • Use markdown where necessary, mostly for code blocks.
    • End with either a period (.) or an exclamation mark (!).
    • Start with a capital letter.
    • Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry.
  • Code style is correct
    (run the linters)

@devonh devonh requested a review from a team as a code owner May 5, 2025 21:56
@devonh devonh changed the base branch from develop to erikj/ss_reject_invites May 5, 2025 22:09
@github-actions github-actions bot deployed to PR Documentation Preview May 5, 2025 22:10 Active
@devonh devonh changed the base branch from erikj/ss_reject_invites to develop May 5, 2025 22:28
@devonh devonh changed the base branch from develop to erikj/ss_reject_invites May 5, 2025 22:29
@devonh devonh changed the base branch from erikj/ss_reject_invites to develop May 5, 2025 22:30
@devonh devonh changed the base branch from develop to erikj/ss_reject_invites May 5, 2025 22:31
@MadLittleMods MadLittleMods changed the title Convert tests to use compute_interested_rooms Convert Sliding Sync tests to use higher-level compute_interested_rooms May 5, 2025
@MadLittleMods MadLittleMods force-pushed the devon/ss_test_refactor branch from 8ff7993 to 6dbaf93 Compare May 6, 2025 00:58
@devonh devonh force-pushed the devon/ss_test_refactor branch from 6dbaf93 to a434892 Compare May 6, 2025 15:43
@devonh devonh changed the base branch from erikj/ss_reject_invites to develop May 6, 2025 15:43
Comment on lines +302 to +309
if filter_membership_for_sync(
user_id=user_id,
room_membership_for_user=room_for_user,
newly_left=room_id in newly_left_room_map,
):
room_membership_for_user_map[room_id] = room_for_user
else:
room_membership_for_user_map.pop(room_id, None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before adding to the room_membership_for_user_map, we now double-check it should be added with the filter_membership_for_sync(...). If it shouldn't be in the map, we also make sure to pop it off.

This is the same thing we're doing in the fallback path just with a lighter touch.

Fallback path (filter_rooms_relevant_for_sync(...) just calls filter_membership_for_sync(...) on each room):

sync_room_map = await self.filter_rooms_relevant_for_sync(
user=sync_config.user,
room_membership_for_user_map=room_membership_for_user_map,
newly_left_room_ids=newly_left_room_ids,
)

The new path avoids the filter_membership_for_sync(...) call because the results should already be filtered since we already avoided all of that work up-front by only pulling out what we need.

sync_room_map = room_membership_for_user_map

Comment on lines 1480 to 1483
AND (
(m.membership != 'leave' OR m.user_id != m.sender)
OR (m.event_stream_ordering > ?)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other important change is here. Previously, we always filtered out all self-leave events.

Now, we still almost always filter them out except for when they occur after our to_token. This is just a quirk so we can properly rewind to a potentially non-self-leave that should be included in the sync response.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic has moved to get_sliding_sync_self_leave_rooms_after_to_token(...)

from_token=now_token,
to_token=now_token,
)
)
room_id_results = set(interested_rooms.lists["foo-list"].ops[0].room_ids)
Copy link
Contributor

@MadLittleMods MadLittleMods May 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@devonh Heads-up, from your refactor, I changed our comparison to actually look at the list of room ID's (interested_rooms.lists["foo-list"].ops[0].room_ids) instead of the interested_rooms.room_membership_for_user_map.

The list of rooms between the new and fallback path will be slightly different (the fallback path includes more rooms in interested_rooms.room_membership_for_user_map, more context in #18399 (comment)) but the list of room ID's being returned will be consistent between both.

This also matches what we're doing in the REST layer tests

self.assertIncludes(
set(response_body["lists"]["foo-list"]["ops"][0]["room_ids"]),
{room_id},
exact=True,
)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah - good to know. That makes sense

Comment on lines +1095 to +1099
# `room_id1` should not show up because it was left before the token range.
# `room_id2` should show up because it is `newly_left` within the token range.
self.assertIncludes(
room_id_results,
{room_id2},
Copy link
Contributor

@MadLittleMods MadLittleMods May 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these tests have materially changed since we are looking at the actual list of room ID's being returned instead of the room_membership_for_user_map which was accurate but included self-leave rooms.

Since we're avoiding pulling self-leave events in the new path, it doesn't make sense to care about that now. We only care about the list of rooms being returned to the user.

There should be a comment explaining any change here though. And I think it all makes sense.

@MadLittleMods MadLittleMods self-assigned this May 6, 2025
@MadLittleMods MadLittleMods removed their assignment May 6, 2025
@@ -0,0 +1 @@
Refactor [MSC4186](https://github.com/matrix-org/matrix-spec-proposals/pull/4186) Simplified Sliding Sync room list tests to cover both new and fallback logic paths.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@devonh You should give this a review pass and then we should potentially put this PR in the review queue for a third party to review.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. I'll take a look through it.
But we should definitely also get some other eyes on it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MadLittleMods Thanks for digging into this!

@devonh devonh requested a review from a team May 6, 2025 22:58
Copy link
Contributor

@reivilibre reivilibre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise seems sensible

Comment on lines +586 to +588
class_name_func=lambda cls,
num,
params_dict: f"{cls.__name__}_{'new' if params_dict['use_new_tables'] else 'fallback'}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wonder if we can convince the formatter to format this differently? This formatting is rather obfuscating

Suggested change
class_name_func=lambda cls,
num,
params_dict: f"{cls.__name__}_{'new' if params_dict['use_new_tables'] else 'fallback'}",
class_name_func=(
lambda cls, num, params_dict:
f"{cls.__name__}_{'new' if params_dict['use_new_tables'] else 'fallback'}"
),

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While the formatter seems to be happy with the alternate formatting, running the tests is not.
I get what you're saying about the formatting being unclear, but these shouldn't stick around too much longer since we can remove the fallback functionality of sliding sync now.

@devonh devonh merged commit ae877aa into develop May 7, 2025
39 checks passed
@devonh devonh deleted the devon/ss_test_refactor branch May 7, 2025 15:08
MatMaul pushed a commit to tchapgouv/synapse that referenced this pull request May 12, 2025
…oms` (element-hq#18399)

Spawning from
element-hq#18375 (comment),

This updates some sliding sync tests to use a higher level function in
order to move test coverage to cover both fallback & new tables.
Important when element-hq#18375 is
merged.

In other words, adjust tests to target `compute_interested_room(...)`
(relevant to both new and fallback path) instead of the lower level
`get_room_membership_for_user_at_to_token(...)` that only applies to the
fallback path.

### Dev notes

```
SYNAPSE_TEST_LOG_LEVEL=INFO poetry run trial tests.handlers.test_sliding_sync.ComputeInterestedRoomsTestCase_new
```

```
SYNAPSE_TEST_LOG_LEVEL=INFO poetry run trial tests.rest.client.sliding_sync
```

```
SYNAPSE_POSTGRES=1 SYNAPSE_POSTGRES_USER=postgres SYNAPSE_TEST_LOG_LEVEL=INFO poetry run trial tests.handlers.test_sliding_sync.ComputeInterestedRoomsTestCase_new.test_display_name_changes_leave_after_token_range
```

### Pull Request Checklist

<!-- Please read
https://element-hq.github.io/synapse/latest/development/contributing_guide.html
before submitting your pull request -->

* [x] Pull request is based on the develop branch
* [x] Pull request includes a [changelog
file](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#changelog).
The entry should:
- Be a short description of your change which makes sense to users.
"Fixed a bug that prevented receiving messages from other servers."
instead of "Moved X method from `EventStore` to `EventWorkerStore`.".
  - Use markdown where necessary, mostly for `code blocks`.
  - End with either a period (.) or an exclamation mark (!).
  - Start with a capital letter.
- Feel free to credit yourself, by adding a sentence "Contributed by
@github_username." or "Contributed by [Your Name]." to the end of the
entry.
* [x] [Code
style](https://element-hq.github.io/synapse/latest/code_style.html) is
correct
(run the
[linters](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#run-the-linters))

---------

Co-authored-by: Eric Eastwood <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants