Skip to content

Commit

Permalink
Check result of deleting realm when immediately running sync file act…
Browse files Browse the repository at this point in the history
…ions (#6237)
  • Loading branch information
jbreams authored Mar 27, 2023
1 parent 775c773 commit 4aa1235
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
### Fixed
* <How do the end-user experience this issue? what was the impact?> ([#????](https://github.com/realm/realm-core/issues/????), since v?.?.?)
* Changing the log level on the fly would not affect the core level log output ([#6440](https://github.com/realm/realm-core/issues/6440), since 13.7.0)
* None.
* `SyncManager::immediately_run_file_actions()` no longer ignores the result of trying to remove a realm. This could have resulted in a client reset action being reported as successful when it actually failed on windows if the `Realm` was still open ([#6050](https://github.com/realm/realm-core/issues/6050)).


### Breaking changes
* None.
Expand Down
3 changes: 1 addition & 2 deletions src/realm/object-store/sync/sync_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,7 @@ bool SyncManager::run_file_action(SyncFileActionMetadata& md)
switch (md.action()) {
case SyncFileActionMetadata::Action::DeleteRealm:
// Delete all the files for the given Realm.
m_file_manager->remove_realm(md.original_name());
return true;
return m_file_manager->remove_realm(md.original_name());
case SyncFileActionMetadata::Action::BackUpThenDeleteRealm:
// Copy the primary Realm file to the recovery dir, and then delete the Realm.
auto new_name = md.new_name();
Expand Down
16 changes: 16 additions & 0 deletions test/object-store/sync/sync_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,23 @@ TEST_CASE("sync_manager: file actions", "[sync]") {
const std::string realm_path_3 = file_manager.realm_file_path(uuid_3, local_uuid_3, realm_url, partition);
const std::string realm_path_4 = file_manager.realm_file_path(uuid_4, local_uuid_4, realm_url, partition);

// On windows you can't delete a realm if the file is open elsewhere.
#ifdef _WIN32
SECTION("Action::DeleteRealm - fails if locked") {
SharedRealm locked_realm;
create_dummy_realm(realm_path_1, &locked_realm);

REQUIRE(locked_realm);

TestSyncManager tsm(config);
manager.make_file_action_metadata(realm_path_1, realm_url, "user1", Action::DeleteRealm);

REQUIRE_FALSE(tsm.app()->sync_manager()->immediately_run_file_actions(realm_path_1));
}
#endif

SECTION("Action::DeleteRealm") {

// Create some file actions
manager.make_file_action_metadata(realm_path_1, realm_url, "user1", Action::DeleteRealm);
manager.make_file_action_metadata(realm_path_2, realm_url, "user2", Action::DeleteRealm);
Expand Down
7 changes: 5 additions & 2 deletions test/object-store/util/test_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,16 @@ std::ostream& operator<<(std::ostream& os, const Exception& e)
return os;
}

bool create_dummy_realm(std::string path)
bool create_dummy_realm(std::string path, std::shared_ptr<Realm>* out)
{
Realm::Config config;
config.path = path;
try {
_impl::RealmCoordinator::get_coordinator(path)->get_realm(config, none);
auto realm = _impl::RealmCoordinator::get_coordinator(path)->get_realm(config, none);
REQUIRE_REALM_EXISTS(path);
if (out) {
*out = std::move(realm);
}
return true;
}
catch (std::exception&) {
Expand Down
3 changes: 2 additions & 1 deletion test/object-store/util/test_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ inline ExceptionMatcher<void> make_exception_matcher(ErrorCodes::Error code, std

std::ostream& operator<<(std::ostream&, const Exception&);

class Realm;
/// Open a Realm at a given path, creating its files.
bool create_dummy_realm(std::string path);
bool create_dummy_realm(std::string path, std::shared_ptr<Realm>* out = nullptr);
void reset_test_directory(const std::string& base_path);
std::vector<char> make_test_encryption_key(const char start = 0);
void catch2_ensure_section_run_workaround(bool did_run_a_section, std::string section_name,
Expand Down

0 comments on commit 4aa1235

Please sign in to comment.