-
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
Allow frozen Realms to be opened with additive schema changes #6693
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -273,7 +273,7 @@ static auto make_client_reset_handler() | |
} | ||
|
||
TEST_CASE("flx: client reset", "[sync][flx][app][client reset]") { | ||
Schema schema{ | ||
std::vector<ObjectSchema> schema{ | ||
{"TopLevel", | ||
{ | ||
{"_id", PropertyType::ObjectId, Property::IsPrimary{true}}, | ||
|
@@ -899,6 +899,59 @@ TEST_CASE("flx: client reset", "[sync][flx][app][client reset]") { | |
sync::make_error_code(sync::ClientError::auto_client_reset_failure)); | ||
} | ||
} | ||
|
||
SECTION("DiscardLocal: schema indexes match in before and after states") { | ||
{ | ||
config_local.sync_config->error_handler = [](std::shared_ptr<SyncSession>, SyncError) { | ||
// ignore spurious failures on this instance | ||
}; | ||
SharedRealm realm = Realm::get_shared_realm(config_local); | ||
subscribe_to_and_add_objects(realm, 1); | ||
auto subs = realm->get_latest_subscription_set(); | ||
auto result = subs.get_state_change_notification(sync::SubscriptionSet::State::Complete).get(); | ||
CHECK(result == sync::SubscriptionSet::State::Complete); | ||
reset_utils::trigger_client_reset(harness.session().app_session(), realm); | ||
realm->close(); | ||
} | ||
{ | ||
Realm::Config config_copy = config_local; | ||
config_copy.sync_config->error_handler = [](std::shared_ptr<SyncSession>, SyncError err) { | ||
FAIL(err); | ||
}; | ||
// reorder a property such that it does not match the on disk property order | ||
std::vector<ObjectSchema> local_schema = schema; | ||
std::swap(local_schema[0].persisted_properties[1], local_schema[0].persisted_properties[2]); | ||
config_copy.schema = local_schema; | ||
config_copy.sync_config->client_resync_mode = ClientResyncMode::Recover; | ||
auto [promise, future] = util::make_promise_future<void>(); | ||
auto shared_promise = std::make_shared<decltype(promise)>(std::move(promise)); | ||
config_copy.sync_config->notify_before_client_reset = [&](SharedRealm frozen_before) { | ||
++before_reset_count; | ||
REQUIRE(frozen_before->schema().size() > 0); | ||
REQUIRE(frozen_before->schema_version() != ObjectStore::NotVersioned); | ||
REQUIRE(frozen_before->schema() == Schema(local_schema)); | ||
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. I see you're comparing the local schema with the frozen realm's schema. Should we also check the column indexes (e.g. 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. The schema has a strongly ordered equality check built in to operator==. I verified that this test failed without the fix. However, it may not be appropriate to rely on that internal behaviour, so I added some extra checks here to ensure that the intent of the test survives any future changes to |
||
}; | ||
config_copy.sync_config->notify_after_client_reset = | ||
[&, promise = std::move(shared_promise)](SharedRealm frozen_before, ThreadSafeReference after_ref, | ||
bool did_recover) { | ||
++after_reset_count; | ||
REQUIRE(frozen_before->schema().size() > 0); | ||
REQUIRE(frozen_before->schema_version() != ObjectStore::NotVersioned); | ||
REQUIRE(frozen_before->schema() == Schema(local_schema)); | ||
SharedRealm after = | ||
Realm::get_shared_realm(std::move(after_ref), util::Scheduler::make_default()); | ||
REQUIRE(after); | ||
REQUIRE(after->schema() == Schema(local_schema)); | ||
REQUIRE(did_recover); | ||
promise->emplace_value(); | ||
}; | ||
|
||
SharedRealm realm = Realm::get_shared_realm(config_copy); | ||
future.get(); | ||
CHECK(before_reset_count == 1); | ||
CHECK(after_reset_count == 1); | ||
} | ||
} | ||
} | ||
|
||
TEST_CASE("flx: creating an object on a class with no subscription throws", "[sync][flx][app]") { | ||
|
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.
Should you update this comment since now the actual schema needs to be a subset of the requested schema?
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.
Updated.