Skip to content

Sliding Sync: Move filters tests to rest layer#17703

Merged
MadLittleMods merged 8 commits into
developfrom
madlittlemods/sliding-sync-move-filters-tests
Sep 12, 2024
Merged

Sliding Sync: Move filters tests to rest layer#17703
MadLittleMods merged 8 commits into
developfrom
madlittlemods/sliding-sync-move-filters-tests

Conversation

@MadLittleMods

@MadLittleMods MadLittleMods commented Sep 11, 2024

Copy link
Copy Markdown
Contributor

Move filters tests to rest layer in order to test the new (with sliding sync tables) and fallback paths that Sliding Sync can use.

Also found a bug in the new path because it's not being tested which is also fixed in this PR. We now take into account has_known_state when filtering.

Spawning from #17662 (comment). This should have been done when we started using the new sliding sync tables in #17630

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)

Comment on lines +1745 to +1748
# Remove rooms if we can't figure out what room type it is
if not sync_room_map[room_id].has_known_state:
filtered_room_id_set.remove(room_id)
continue

@MadLittleMods MadLittleMods Sep 11, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixing filter_rooms_using_tables (the new path using the new sliding sync tables) to take into account has_known_state.

The _no_stripped_state tests exercise these scenarios.

Found this bug because we're actually testing the new path now with this PR.

response_body["rooms"][room_id]["bump_stamp"], invite_pos.stream
)

def test_rooms_meta_is_dm(self) -> None:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This test is "new" because I moved the "Ensure DM's are correctly marked" checking from one of the filtering tests to it's own separate thing here.

)

def test_filters_is_dm(self) -> None:
"""

@MadLittleMods MadLittleMods Sep 11, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These tests existed before as unit tests against filter_rooms(...) directly but now that we also have filter_rooms_using_tables(...) they've been migrated to integration tests at the REST layer operating against the Sliding Sync API itself. This way we can test both code paths with the same tests.

They are just refactored to be at this new layer and interact with the API.

# There should be no room sent down.
self.assertFalse(channel.json_body["rooms"])

def test_filter_list(self) -> None:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These filter tests already at the REST layer were just moved to tests/rest/client/sliding_sync/test_lists_filters.py now that we have a specific file for it.

message=str(actual_required_state),
)

def _add_new_dm_to_global_account_data(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Just moving some helpers to the SlidingSyncBase so we can use them across the Sliding Sync tests more easily.

self.assertTrue(room_id1 in newly_left)


class FilterRoomsTestCase(HomeserverTestCase):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These tests we're moved to tests/rest/client/sliding_sync/test_lists_filters.py and refactored to interact with the Sliding Sync API directly.

@MadLittleMods MadLittleMods marked this pull request as ready for review September 12, 2024 00:44
@MadLittleMods MadLittleMods requested a review from a team as a code owner September 12, 2024 00:44

@devonh devonh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall looks good to me!
Just a few comments.

}
response_body, _ = self.do_sync(sync_body, tok=user1_tok)
self.assertIncludes(
set(response_body["lists"]["foo-list"]["ops"][0]["room_ids"]),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not an issue here, but the ops field in sync responses is completely omitted from the MSC. ie. https://github.com/matrix-org/matrix-spec-proposals/blob/erikj/sss/proposals/4186-simplified-sliding-sync.md#response-format

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We're thinking about removing it in favor of just a straight list like room_ids: [] but until then I'll use it (context #17671 (comment))

Comment thread tests/rest/client/sliding_sync/test_lists_filters.py
Comment thread tests/rest/client/sliding_sync/test_lists_filters.py
@MadLittleMods MadLittleMods merged commit 9b83fb7 into develop Sep 12, 2024
@MadLittleMods MadLittleMods deleted the madlittlemods/sliding-sync-move-filters-tests branch September 12, 2024 20:27
@MadLittleMods

Copy link
Copy Markdown
Contributor Author

Thanks for the review @devonh 🦌

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.

2 participants