Skip to content

Commit

Permalink
Make TestFile non-copyable
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tgoyne committed Sep 27, 2023
1 parent a9c8f99 commit 8cc99bb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion test/object-store/realm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
{
Expand Down
19 changes: 8 additions & 11 deletions test/object-store/sync/flx_sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<SyncConfig>(*config_copy.sync_config);
config_copy.sync_config->error_handler = nullptr;
auto&& [reset_future, reset_handler] = make_client_reset_handler();
Expand Down Expand Up @@ -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);
Expand All @@ -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<SyncSession>, SyncError err) {
REALM_ASSERT_EX(!err.is_fatal, err.status);
Expand Down Expand Up @@ -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 };
Expand Down
8 changes: 4 additions & 4 deletions test/object-store/thread_safe_reference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Results>(realm_in_thread);
REQUIRE(resolved_results.size() == 1);
Expand All @@ -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<Object>(realm_in_thread);
REQUIRE(resolved_object.is_valid());
Expand Down Expand Up @@ -569,7 +569,7 @@ TEST_CASE("thread safe reference") {
REQUIRE(results.get<int64_t>(1) == 1);
REQUIRE(results.get<int64_t>(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<Results>(r);
Expand Down Expand Up @@ -621,7 +621,7 @@ TEST_CASE("thread safe reference") {
REQUIRE(results.get<int64_t>(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<Results>(r);
Expand Down
3 changes: 3 additions & 0 deletions test/object-store/util/test_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit 8cc99bb

Please sign in to comment.