-
Notifications
You must be signed in to change notification settings - Fork 336
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
Conversation
compute_interested_rooms
8ff7993
to
6dbaf93
Compare
6dbaf93
to
a434892
Compare
This reverts commit d2a4179960e266dc35a06e28c08015570c9a4b21.
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) |
There was a problem hiding this comment.
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):
synapse/synapse/handlers/sliding_sync/room_lists.py
Lines 596 to 600 in d0873d5
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 |
AND ( | ||
(m.membership != 'leave' OR m.user_id != m.sender) | ||
OR (m.event_stream_ordering > ?) | ||
) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
synapse/tests/rest/client/sliding_sync/test_sliding_sync.py
Lines 664 to 668 in 740fc88
self.assertIncludes( | |
set(response_body["lists"]["foo-list"]["ops"][0]["room_ids"]), | |
{room_id}, | |
exact=True, | |
) |
There was a problem hiding this comment.
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
# `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}, |
There was a problem hiding this comment.
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.
@@ -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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
otherwise seems sensible
class_name_func=lambda cls, | ||
num, | ||
params_dict: f"{cls.__name__}_{'new' if params_dict['use_new_tables'] else 'fallback'}", |
There was a problem hiding this comment.
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
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'}" | |
), |
There was a problem hiding this comment.
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.
…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]>
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 levelget_room_membership_for_user_at_to_token(...)
that only applies to the fallback path.Dev notes
Pull Request Checklist
EventStore
toEventWorkerStore
.".code blocks
.(run the linters)