@@ -613,6 +613,83 @@ TEST_CASE("app metadata: persisted", "[sync][metadata]") {
613613 }
614614}
615615
616+ TEST_CASE (" app metadata: multiple stores" , " [sync][metadata]" ) {
617+ test_util::TestDirGuard test_dir (base_path);
618+
619+ AppConfig config;
620+ config.app_id = " app id" ;
621+ config.metadata_mode = AppConfig::MetadataMode::NoEncryption;
622+ config.base_file_path = base_path;
623+ SyncFileManager file_manager (config);
624+
625+ auto store_1 = create_metadata_store (config, file_manager);
626+ auto store_2 = create_metadata_store (config, file_manager);
627+ REQUIRE (store_1 != store_2);
628+
629+ SECTION (" create user in one store then read from the other" ) {
630+ store_1->create_user (user_id, refresh_token, access_token, device_id);
631+ auto user = store_2->get_user (user_id);
632+ REQUIRE (user);
633+ }
634+
635+ SECTION (" update existing user in one store then read from the other" ) {
636+ store_1->create_user (user_id, refresh_token, access_token, device_id);
637+ auto user_1 = store_1->get_user (user_id);
638+
639+ std::vector<UserIdentity> identities{{" identity" , " provider" }};
640+ store_2->update_user (user_id, [&](UserData& data) {
641+ data.identities = identities;
642+ });
643+
644+ auto user_2 = store_1->get_user (user_id);
645+ CHECK (user_1->identities .empty ());
646+ CHECK (user_2->identities == identities);
647+ }
648+
649+ SECTION (" non-conflicting writes from multiple stores" ) {
650+ store_1->create_user (user_id, refresh_token, access_token, device_id);
651+ auto user_1 = store_1->get_user (user_id);
652+ auto user_2 = store_2->get_user (user_id);
653+
654+ UserProfile profile = bson::BsonDocument{{" name" , " user's name" }, {" email" , " user's email" }};
655+ std::vector<UserIdentity> identities{{" identity" , " provider" }};
656+ store_1->update_user (user_id, [&](UserData& data) {
657+ data.identities = identities;
658+ });
659+ store_2->update_user (user_id, [&](UserData& data) {
660+ data.profile = profile;
661+ });
662+
663+ // The second write should not have discarded the change made by the first store
664+ user_1 = store_1->get_user (user_id);
665+ user_2 = store_2->get_user (user_id);
666+ REQUIRE (user_1->identities == user_2->identities );
667+ REQUIRE (user_1->identities == identities);
668+ REQUIRE (user_1->profile .data () == user_2->profile .data ());
669+ REQUIRE (user_1->profile .data () == profile.data ());
670+ }
671+
672+ SECTION (" file actions are not performed on open if there is already a live store" ) {
673+ auto path = util::make_temp_file (" file_to_delete" );
674+ store_1->create_user (user_id, refresh_token, access_token, device_id);
675+ store_1->add_realm_path (user_id, path);
676+ store_1->log_out (user_id, SyncUser::State::Removed);
677+
678+ create_metadata_store (config, file_manager);
679+ REQUIRE (File::exists (path));
680+
681+ store_1.reset ();
682+
683+ create_metadata_store (config, file_manager);
684+ REQUIRE (File::exists (path));
685+
686+ store_2.reset ();
687+
688+ create_metadata_store (config, file_manager);
689+ REQUIRE_FALSE (File::exists (path));
690+ }
691+ }
692+
616693#if REALM_ENABLE_ENCRYPTION
617694TEST_CASE (" app metadata: encryption" , " [sync][metadata]" ) {
618695 test_util::TestDirGuard test_dir (base_path);
@@ -739,7 +816,7 @@ TEST_CASE("app metadata: encryption", "[sync][metadata]") {
739816#endif // REALM_PLATFORM_APPLE
740817}
741818
742- #endif
819+ #endif // REALM_ENABLE_ENCRYPTION
743820
744821#ifndef SWIFT_PACKAGE // The SPM build currently doesn't copy resource files
745822TEST_CASE (" sync metadata: can open old metadata realms" , " [sync][metadata]" ) {
0 commit comments