From 8cc99bb379c5a7351de3abc0b1eec9363f20cd4b Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Wed, 27 Sep 2023 08:54:05 -0700 Subject: [PATCH] Make TestFile non-copyable It's unclear if this actually caused any problems, but there were a number of places where we were deleting Realm files while they were in use due to copying a TestFile and then deleting the copy when we actually wanted to copy the config. --- test/object-store/realm.cpp | 2 +- test/object-store/sync/flx_sync.cpp | 19 ++++++++----------- test/object-store/thread_safe_reference.cpp | 8 ++++---- test/object-store/util/test_file.hpp | 3 +++ 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/test/object-store/realm.cpp b/test/object-store/realm.cpp index 4cd47753832..e6e3db87ee4 100644 --- a/test/object-store/realm.cpp +++ b/test/object-store/realm.cpp @@ -3561,7 +3561,7 @@ TEST_CASE("SharedRealm: SchemaChangedFunction") { size_t schema_changed_called = 0; Schema changed_fixed_schema; TestFile config; - auto dynamic_config = config; + RealmConfig dynamic_config = config; config.schema = Schema{{"object1", { diff --git a/test/object-store/sync/flx_sync.cpp b/test/object-store/sync/flx_sync.cpp index 1ca2bc301f6..d2cb1554205 100644 --- a/test/object-store/sync/flx_sync.cpp +++ b/test/object-store/sync/flx_sync.cpp @@ -611,7 +611,7 @@ TEST_CASE("flx: client reset", "[sync][flx][client reset][baas]") { // Remove the folder preventing the completion of a client reset. util::try_remove_dir_recursive(fresh_path); - auto config_copy = config_local; + RealmConfig config_copy = config_local; config_copy.sync_config = std::make_shared(*config_copy.sync_config); config_copy.sync_config->error_handler = nullptr; auto&& [reset_future, reset_handler] = make_client_reset_handler(); @@ -837,7 +837,7 @@ TEST_CASE("flx: client reset", "[sync][flx][client reset][baas]") { test_reset->make_local_changes(std::move(make_local_changes_that_will_fail)) ->on_post_reset(std::move(verify_post_reset_state)) ->run(); - auto config_copy = config_local; + RealmConfig config_copy = config_local; auto&& [error_future2, err_handler2] = make_error_handler(); config_copy.sync_config->error_handler = err_handler2; auto realm_post_reset = Realm::get_shared_realm(config_copy); @@ -855,7 +855,7 @@ TEST_CASE("flx: client reset", "[sync][flx][client reset][baas]") { ->on_post_reset(std::move(verify_post_reset_state)) ->run(); - auto config_copy = config_local; + RealmConfig config_copy = config_local; auto&& [client_reset_future, reset_handler] = make_client_reset_handler(); config_copy.sync_config->error_handler = [](std::shared_ptr, SyncError err) { REALM_ASSERT_EX(!err.is_fatal, err.status); @@ -1020,15 +1020,12 @@ TEST_CASE("flx: client reset", "[sync][flx][client reset][baas]") { REQUIRE(sync_error.status == ErrorCodes::AutoClientResetFailed); // Open the realm again. This should not crash. - { - auto config_copy = config_local; - auto&& [err_future, err_handler] = make_error_handler(); - config_local.sync_config->error_handler = err_handler; + auto&& [err_future, err_handler] = make_error_handler(); + config_local.sync_config->error_handler = err_handler; - auto realm_post_reset = Realm::get_shared_realm(config_copy); - auto sync_error = wait_for_future(std::move(err_future)).get(); - REQUIRE(sync_error.status == ErrorCodes::AutoClientResetFailed); - } + auto realm_post_reset = Realm::get_shared_realm(config_local); + sync_error = wait_for_future(std::move(err_future)).get(); + REQUIRE(sync_error.status == ErrorCodes::AutoClientResetFailed); } enum class ResetMode { NoReset, InitiateClientReset }; diff --git a/test/object-store/thread_safe_reference.cpp b/test/object-store/thread_safe_reference.cpp index 274ae1688ac..883154152bc 100644 --- a/test/object-store/thread_safe_reference.cpp +++ b/test/object-store/thread_safe_reference.cpp @@ -332,7 +332,7 @@ TEST_CASE("thread safe reference") { SECTION("read-only `ThreadSafeReference` to `Results`") { auto thread_safe_results = ThreadSafeReference(results); - JoiningThread([thread_safe_results = std::move(thread_safe_results), config, int_obj_col]() mutable { + JoiningThread([&thread_safe_results, &config, int_obj_col]() mutable { SharedRealm realm_in_thread = Realm::get_shared_realm(config); Results resolved_results = thread_safe_results.resolve(realm_in_thread); REQUIRE(resolved_results.size() == 1); @@ -343,7 +343,7 @@ TEST_CASE("thread safe reference") { SECTION("read-only `ThreadSafeReference` to an `Object`") { Object object(read_only_realm, results.get(0)); auto thread_safe_object = ThreadSafeReference(object); - JoiningThread([thread_safe_object = std::move(thread_safe_object), config, int_obj_col]() mutable { + JoiningThread([&thread_safe_object, &config, int_obj_col]() mutable { SharedRealm realm_in_thread = Realm::get_shared_realm(config); auto resolved_object = thread_safe_object.resolve(realm_in_thread); REQUIRE(resolved_object.is_valid()); @@ -569,7 +569,7 @@ TEST_CASE("thread safe reference") { REQUIRE(results.get(1) == 1); REQUIRE(results.get(2) == 2); auto ref = ThreadSafeReference(results); - JoiningThread([ref = std::move(ref), config]() mutable { + JoiningThread([&ref, &config]() mutable { config.scheduler = util::Scheduler::make_frozen(VersionID()); SharedRealm r = Realm::get_shared_realm(config); Results results = ref.resolve(r); @@ -621,7 +621,7 @@ TEST_CASE("thread safe reference") { REQUIRE(results.get(2) == 3); auto ref = ThreadSafeReference(results); - JoiningThread([ref = std::move(ref), config]() mutable { + JoiningThread([&ref, &config]() mutable { config.scheduler = util::Scheduler::make_frozen(VersionID()); SharedRealm r = Realm::get_shared_realm(config); Results results = ref.resolve(r); diff --git a/test/object-store/util/test_file.hpp b/test/object-store/util/test_file.hpp index 6e10a0581be..1bb2eb154b7 100644 --- a/test/object-store/util/test_file.hpp +++ b/test/object-store/util/test_file.hpp @@ -73,6 +73,9 @@ struct TestFile : realm::Realm::Config { TestFile(); ~TestFile(); + TestFile(const TestFile&) = delete; + TestFile& operator=(const TestFile&) = delete; + // The file should outlive the object, ie. should not be deleted in destructor void persist() {