Skip to content
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

Begin decoupling sync tests from App #7351

Merged
merged 3 commits into from
Feb 20, 2024
Merged

Begin decoupling sync tests from App #7351

merged 3 commits into from
Feb 20, 2024

Conversation

tgoyne
Copy link
Member

@tgoyne tgoyne commented Feb 16, 2024

Another pile of changes extracted from #7300 with the hopes of making it more reviewable.

The primary change here is that TestSyncManager no longer has an App, and a new type OfflineAppSession replaces it for things testing App using a mock transport. Our test types are now:

  • TestSyncManager: initializes a SyncManager and SyncServer for testing sync functionality. Does not use any App Services1 or BaaS.
  • OfflineAppSession: initializes an App using a mock network transport. Does not support sync, and is used for unit tests of App Services functionality
  • TestAppSession: initializes an App using a real network transport that talks to BaaS. Used for integration tests and sync tests which can't be tested against the old server.

This removes the ability to reconfigure SyncManager after calling reset_for_testing(). This was something that was originally needed because SyncManager was a singleton, but that hasn't been the case ever since v10 and tests can now just create a new SyncManager. No one appears to have been relying on this. reset_for_testing() has been renamed to tear_down_for_testing() to reflect the change in functionality.

Footnotes

  1. Or won't post-app services split, anyway. Currently the actual implementation is still fairly coupled.

@tgoyne tgoyne self-assigned this Feb 16, 2024
@cla-bot cla-bot bot added the cla: yes label Feb 16, 2024
Copy link

coveralls-official bot commented Feb 16, 2024

Pull Request Test Coverage Report for Build thomas.goyne_179

Details

  • 518 of 539 (96.1%) changed or added relevant lines in 23 files are covered.
  • 203 unchanged lines in 21 files lost coverage.
  • Overall coverage decreased (-0.04%) to 91.854%

Changes Missing Coverage Covered Lines Changed/Added Lines %
test/object-store/util/test_file.hpp 16 20 80.0%
test/object-store/util/test_file.cpp 48 54 88.89%
test/object-store/sync/app.cpp 180 191 94.24%
Files with Coverage Reduction New Missed Lines %
test/test_dictionary.cpp 1 99.85%
test/test_index_string.cpp 1 94.13%
src/realm/object-store/sync/app.cpp 2 92.03%
src/realm/object-store/sync/impl/sync_metadata.cpp 2 97.27%
src/realm/object-store/sync/sync_session.cpp 2 93.51%
src/realm/query_expression.hpp 2 93.52%
src/realm/sync/network/http.hpp 2 82.41%
src/realm/uuid.cpp 2 97.01%
src/realm/sync/client.cpp 3 91.07%
src/realm/sync/network/network.cpp 3 89.66%
Totals Coverage Status
Change from base Build 2041: -0.04%
Covered Lines: 235290
Relevant Lines: 256156

💛 - Coveralls

Co-authored-by: James Stone <james.stone@mongodb.com>
@tgoyne tgoyne marked this pull request as ready for review February 17, 2024 00:04
@@ -22,7 +22,7 @@
* Fix a minor race condition when backing up Realm files before a client reset which could have lead to overwriting an existing file. ([PR #7341](https://github.com/realm/realm-core/pull/7341)).

### Breaking changes
* None.
* SyncManager no longer supports reconfiguring after calling reset_for_testing(). SyncManager::configure() has been folded into the constructor, and reset_for_testing() has been renamed to tear_down_for_testing(). ([PR #7351](https://github.com/realm/realm-core/pull/7351))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if this should be under internals section. Are users supposed to use reset_for_testing?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a breaking change for the SDKs which use it in their tests.

Copy link
Collaborator

Choose a reason for hiding this comment

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

right. but don't we share the breaking changes with the users?

Copy link
Member Author

Choose a reason for hiding this comment

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

The SDKs are the users of core. They should not copy and paste this into their own changelogs.

@tgoyne tgoyne merged commit 3cf7aa7 into master Feb 20, 2024
37 checks passed
@tgoyne tgoyne deleted the tg/test-refactoring branch February 20, 2024 22:42
Copy link
Contributor

@michael-wb michael-wb left a comment

Choose a reason for hiding this comment

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

LGTM - oh, it looks like you just merged.

@@ -78,7 +78,7 @@ util::Optional<std::string> to_optional_string(StringData sd)
std::vector<AuditEvent> get_audit_events(TestSyncManager& manager, bool parse_events = true)
{
// Wait for all sessions to be fully uploaded and then tear them down
auto sync_manager = manager.app()->sync_manager();
auto sync_manager = manager.sync_manager();
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! These changes are definitely a lot cleaner

auto user = app->sync_manager()->get_user("user", ENCODE_FAKE_JWT("not_a_real_token"),
ENCODE_FAKE_JWT("also_not_a_real_token"), dummy_device_id);
TestSyncManager tsm;
auto user = tsm.fake_user();
Copy link
Contributor

Choose a reason for hiding this comment

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

💯

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants