-
Notifications
You must be signed in to change notification settings - Fork 168
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! These changes are definitely a lot cleaner |
||
REALM_ASSERT(sync_manager); | ||
auto sessions = sync_manager->get_all_sessions(); | ||
for (auto& session : sessions) { | ||
|
@@ -265,7 +265,7 @@ struct TestClock { | |
|
||
TEST_CASE("audit object serialization", "[sync][pbs][audit]") { | ||
TestSyncManager test_session; | ||
SyncTestFile config(test_session.app(), "parent"); | ||
SyncTestFile config(test_session, "parent"); | ||
config.automatic_change_notifications = false; | ||
config.schema_version = 1; | ||
config.schema = Schema{ | ||
|
@@ -1066,7 +1066,7 @@ TEST_CASE("audit management", "[sync][pbs][audit]") { | |
TestClock clock; | ||
|
||
TestSyncManager test_session; | ||
SyncTestFile config(test_session.app(), "parent"); | ||
SyncTestFile config(test_session, "parent"); | ||
config.automatic_change_notifications = false; | ||
config.schema_version = 1; | ||
config.schema = Schema{ | ||
|
@@ -1087,7 +1087,7 @@ TEST_CASE("audit management", "[sync][pbs][audit]") { | |
realm->sync_session()->close(); | ||
|
||
SECTION("config validation") { | ||
SyncTestFile config(test_session.app(), "parent2"); | ||
SyncTestFile config(test_session, "parent2"); | ||
config.automatic_change_notifications = false; | ||
config.audit_config = std::make_shared<AuditConfig>(); | ||
SECTION("invalid prefix") { | ||
|
@@ -1495,7 +1495,7 @@ TEST_CASE("audit realm sharding", "[sync][pbs][audit]") { | |
// a lot of local unuploaded data. | ||
TestSyncManager test_session{{}, {.start_immediately = false}}; | ||
|
||
SyncTestFile config(test_session.app(), "parent"); | ||
SyncTestFile config(test_session, "parent"); | ||
config.automatic_change_notifications = false; | ||
config.schema_version = 1; | ||
config.schema = Schema{ | ||
|
@@ -1572,7 +1572,7 @@ TEST_CASE("audit realm sharding", "[sync][pbs][audit]") { | |
auto close_all_sessions = [&] { | ||
realm->close(); | ||
realm = nullptr; | ||
auto sync_manager = test_session.app()->sync_manager(); | ||
auto sync_manager = test_session.sync_manager(); | ||
for (auto& session : sync_manager->get_all_sessions()) { | ||
session->shutdown_and_wait(); | ||
} | ||
|
@@ -1604,7 +1604,7 @@ TEST_CASE("audit realm sharding", "[sync][pbs][audit]") { | |
test_session.sync_server().start(); | ||
|
||
// Open a different Realm with the same user and audit prefix | ||
SyncTestFile config(test_session.app(), "other"); | ||
SyncTestFile config(test_session, "other"); | ||
config.audit_config = std::make_shared<AuditConfig>(); | ||
config.audit_config->logger = audit_logger; | ||
auto realm = Realm::get_shared_realm(config); | ||
|
@@ -1631,7 +1631,7 @@ TEST_CASE("audit realm sharding", "[sync][pbs][audit]") { | |
test_session.sync_server().start(); | ||
|
||
// Open the same Realm with a different audit prefix | ||
SyncTestFile config(test_session.app(), "parent"); | ||
SyncTestFile config(test_session, "parent"); | ||
config.audit_config = std::make_shared<AuditConfig>(); | ||
config.audit_config->logger = audit_logger; | ||
config.audit_config->partition_value_prefix = "other"; | ||
|
@@ -1719,7 +1719,7 @@ TEST_CASE("audit integration tests", "[sync][pbs][audit][baas]") { | |
realm->sync_session()->close(); | ||
generate_event(realm); | ||
|
||
auto events = get_audit_events_from_baas(session, *config.sync_config->user, 1); | ||
auto events = get_audit_events_from_baas(session, *session.app()->current_user(), 1); | ||
REQUIRE(events.size() == 1); | ||
REQUIRE(events[0].activity == "scope"); | ||
REQUIRE(events[0].event == "read"); | ||
|
@@ -1728,18 +1728,20 @@ TEST_CASE("audit integration tests", "[sync][pbs][audit][baas]") { | |
} | ||
|
||
SECTION("different user from parent Realm") { | ||
auto sync_user = session.app()->current_user(); | ||
create_user_and_log_in(session.app()); | ||
config.audit_config->audit_user = session.app()->current_user(); | ||
auto audit_user = session.app()->current_user(); | ||
config.audit_config->audit_user = audit_user; | ||
auto realm = Realm::get_shared_realm(config); | ||
// If audit uses the sync user this'll make it fail as that user is logged out | ||
config.sync_config->user->log_out(); | ||
sync_user->log_out(); | ||
|
||
generate_event(realm); | ||
REQUIRE(get_audit_events_from_baas(session, *config.audit_config->audit_user, 1).size() == 1); | ||
REQUIRE(get_audit_events_from_baas(session, *audit_user, 1).size() == 1); | ||
} | ||
|
||
SECTION("different app from parent Realm") { | ||
auto audit_user = config.sync_config->user; | ||
auto audit_user = session.app()->current_user(); | ||
|
||
// Create an app which does not include AuditEvent in the schema so that | ||
// things will break if audit tries to use it | ||
|
@@ -1766,7 +1768,7 @@ TEST_CASE("audit integration tests", "[sync][pbs][audit][baas]") { | |
generate_event(realm, 3); | ||
|
||
using Metadata = std::map<std::string, std::string>; | ||
auto events = get_audit_events_from_baas(session, *config.sync_config->user, 4); | ||
auto events = get_audit_events_from_baas(session, *session.app()->current_user(), 4); | ||
REQUIRE(events[0].metadata.empty()); | ||
REQUIRE(events[1].metadata == Metadata({{"metadata 1", "value 1"}})); | ||
REQUIRE(events[2].metadata == Metadata({{"metadata 2", "value 2"}})); | ||
|
@@ -1785,7 +1787,7 @@ TEST_CASE("audit integration tests", "[sync][pbs][audit][baas]") { | |
auto audit_user = session.app()->current_user(); | ||
config.audit_config->audit_user = audit_user; | ||
auto realm = Realm::get_shared_realm(config); | ||
session.app()->sync_manager()->remove_user(audit_user->identity()); | ||
session.sync_manager()->remove_user(audit_user->identity()); | ||
|
||
auto audit = realm->audit_context(); | ||
auto scope = audit->begin_scope("scope"); | ||
|
@@ -1814,7 +1816,7 @@ TEST_CASE("audit integration tests", "[sync][pbs][audit][baas]") { | |
} | ||
|
||
SECTION("incoming changesets are discarded") { | ||
app::MongoClient remote_client = config.sync_config->user->mongo_client("BackingDB"); | ||
app::MongoClient remote_client = session.app()->current_user()->mongo_client("BackingDB"); | ||
app::MongoDatabase db = remote_client.db(session.app_session().config.mongo_dbname); | ||
app::MongoCollection collection = db["AuditEvent"]; | ||
|
||
|
@@ -1905,7 +1907,7 @@ TEST_CASE("audit integration tests", "[sync][pbs][audit][baas]") { | |
|
||
realm->sync_session()->force_close(); | ||
generate_event(realm, 0); | ||
get_audit_events_from_baas(session, *config.audit_config->audit_user, 1); | ||
get_audit_events_from_baas(session, *session.app()->current_user(), 1); | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I wonder if this should be under internals section. Are users supposed to use reset_for_testing?
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.
It's a breaking change for the SDKs which use it in their tests.
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.
right. but don't we share the breaking changes with the users?
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.
The SDKs are the users of core. They should not copy and paste this into their own changelogs.