Skip to content

Commit c650e16

Browse files
committed
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.
1 parent 035f66c commit c650e16

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

test/object-store/realm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3561,7 +3561,7 @@ TEST_CASE("SharedRealm: SchemaChangedFunction") {
35613561
size_t schema_changed_called = 0;
35623562
Schema changed_fixed_schema;
35633563
TestFile config;
3564-
auto dynamic_config = config;
3564+
RealmConfig dynamic_config = config;
35653565

35663566
config.schema = Schema{{"object1",
35673567
{

test/object-store/sync/flx_sync.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ TEST_CASE("flx: client reset", "[sync][flx][client reset][baas]") {
611611
// Remove the folder preventing the completion of a client reset.
612612
util::try_remove_dir_recursive(fresh_path);
613613

614-
auto config_copy = config_local;
614+
RealmConfig config_copy = config_local;
615615
config_copy.sync_config = std::make_shared<SyncConfig>(*config_copy.sync_config);
616616
config_copy.sync_config->error_handler = nullptr;
617617
auto&& [reset_future, reset_handler] = make_client_reset_handler();
@@ -837,7 +837,7 @@ TEST_CASE("flx: client reset", "[sync][flx][client reset][baas]") {
837837
test_reset->make_local_changes(std::move(make_local_changes_that_will_fail))
838838
->on_post_reset(std::move(verify_post_reset_state))
839839
->run();
840-
auto config_copy = config_local;
840+
RealmConfig config_copy = config_local;
841841
auto&& [error_future2, err_handler2] = make_error_handler();
842842
config_copy.sync_config->error_handler = err_handler2;
843843
auto realm_post_reset = Realm::get_shared_realm(config_copy);
@@ -855,7 +855,7 @@ TEST_CASE("flx: client reset", "[sync][flx][client reset][baas]") {
855855
->on_post_reset(std::move(verify_post_reset_state))
856856
->run();
857857

858-
auto config_copy = config_local;
858+
RealmConfig config_copy = config_local;
859859
auto&& [client_reset_future, reset_handler] = make_client_reset_handler();
860860
config_copy.sync_config->error_handler = [](std::shared_ptr<SyncSession>, SyncError err) {
861861
REALM_ASSERT_EX(!err.is_fatal, err.status);
@@ -1020,15 +1020,12 @@ TEST_CASE("flx: client reset", "[sync][flx][client reset][baas]") {
10201020
REQUIRE(sync_error.status == ErrorCodes::AutoClientResetFailed);
10211021

10221022
// Open the realm again. This should not crash.
1023-
{
1024-
auto config_copy = config_local;
1025-
auto&& [err_future, err_handler] = make_error_handler();
1026-
config_local.sync_config->error_handler = err_handler;
1023+
auto&& [err_future, err_handler] = make_error_handler();
1024+
config_local.sync_config->error_handler = err_handler;
10271025

1028-
auto realm_post_reset = Realm::get_shared_realm(config_copy);
1029-
auto sync_error = wait_for_future(std::move(err_future)).get();
1030-
REQUIRE(sync_error.status == ErrorCodes::AutoClientResetFailed);
1031-
}
1026+
auto realm_post_reset = Realm::get_shared_realm(config_local);
1027+
sync_error = wait_for_future(std::move(err_future)).get();
1028+
REQUIRE(sync_error.status == ErrorCodes::AutoClientResetFailed);
10321029
}
10331030

10341031
enum class ResetMode { NoReset, InitiateClientReset };

test/object-store/thread_safe_reference.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ TEST_CASE("thread safe reference") {
332332

333333
SECTION("read-only `ThreadSafeReference` to `Results`") {
334334
auto thread_safe_results = ThreadSafeReference(results);
335-
JoiningThread([thread_safe_results = std::move(thread_safe_results), config, int_obj_col]() mutable {
335+
JoiningThread([&thread_safe_results, &config, int_obj_col]() mutable {
336336
SharedRealm realm_in_thread = Realm::get_shared_realm(config);
337337
Results resolved_results = thread_safe_results.resolve<Results>(realm_in_thread);
338338
REQUIRE(resolved_results.size() == 1);
@@ -343,7 +343,7 @@ TEST_CASE("thread safe reference") {
343343
SECTION("read-only `ThreadSafeReference` to an `Object`") {
344344
Object object(read_only_realm, results.get(0));
345345
auto thread_safe_object = ThreadSafeReference(object);
346-
JoiningThread([thread_safe_object = std::move(thread_safe_object), config, int_obj_col]() mutable {
346+
JoiningThread([&thread_safe_object, &config, int_obj_col]() mutable {
347347
SharedRealm realm_in_thread = Realm::get_shared_realm(config);
348348
auto resolved_object = thread_safe_object.resolve<Object>(realm_in_thread);
349349
REQUIRE(resolved_object.is_valid());
@@ -569,7 +569,7 @@ TEST_CASE("thread safe reference") {
569569
REQUIRE(results.get<int64_t>(1) == 1);
570570
REQUIRE(results.get<int64_t>(2) == 2);
571571
auto ref = ThreadSafeReference(results);
572-
JoiningThread([ref = std::move(ref), config]() mutable {
572+
JoiningThread([&ref, &config]() mutable {
573573
config.scheduler = util::Scheduler::make_frozen(VersionID());
574574
SharedRealm r = Realm::get_shared_realm(config);
575575
Results results = ref.resolve<Results>(r);
@@ -621,7 +621,7 @@ TEST_CASE("thread safe reference") {
621621
REQUIRE(results.get<int64_t>(2) == 3);
622622

623623
auto ref = ThreadSafeReference(results);
624-
JoiningThread([ref = std::move(ref), config]() mutable {
624+
JoiningThread([&ref, &config]() mutable {
625625
config.scheduler = util::Scheduler::make_frozen(VersionID());
626626
SharedRealm r = Realm::get_shared_realm(config);
627627
Results results = ref.resolve<Results>(r);

test/object-store/util/test_file.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ struct TestFile : realm::Realm::Config {
7373
TestFile();
7474
~TestFile();
7575

76+
TestFile(const TestFile&) = delete;
77+
TestFile& operator=(const TestFile&) = delete;
78+
7679
// The file should outlive the object, ie. should not be deleted in destructor
7780
void persist()
7881
{

0 commit comments

Comments
 (0)