diff --git a/test/object-store/sync/flx_sync.cpp b/test/object-store/sync/flx_sync.cpp index 51100551509..bd6afe7b0ed 100644 --- a/test/object-store/sync/flx_sync.cpp +++ b/test/object-store/sync/flx_sync.cpp @@ -1383,8 +1383,8 @@ TEST_CASE("flx: geospatial", "[sync][flx][app]") { size_t local_matches = query.find_all().size(); REQUIRE(local_matches == 2); - reset_utils::wait_for_object_to_persist_to_atlas( - harness->app()->current_user(), harness->session().app_session(), "restaurant", {{"_id", pk}}); + reset_utils::wait_for_num_objects_in_atlas( + harness->app()->current_user(), harness->session().app_session(), "restaurant", points.size()); bson::BsonDocument filter = make_polygon_filter(bounds); size_t server_results = run_query_on_server(filter); diff --git a/test/object-store/sync/sync_test_utils.cpp b/test/object-store/sync/sync_test_utils.cpp index dece34092f4..391957bbce7 100644 --- a/test/object-store/sync/sync_test_utils.cpp +++ b/test/object-store/sync/sync_test_utils.cpp @@ -409,6 +409,32 @@ void wait_for_object_to_persist_to_atlas(std::shared_ptr user, const A std::chrono::minutes(15), std::chrono::milliseconds(500)); } +void wait_for_num_objects_in_atlas(std::shared_ptr user, const AppSession& app_session, + const std::string& schema_name, size_t expected_size) +{ + app::MongoClient remote_client = user->mongo_client("BackingDB"); + app::MongoDatabase db = remote_client.db(app_session.config.mongo_dbname); + app::MongoCollection object_coll = db[schema_name]; + + const bson::BsonDocument& filter_bson{}; + timed_sleeping_wait_for( + [&]() -> bool { + auto pf = util::make_promise_future(); + object_coll.count(filter_bson, [promise = std::move(pf.promise)]( + uint64_t count, util::Optional error) mutable { + REQUIRE(!error); + if (error) { + promise.set_error({ErrorCodes::RuntimeError, error->reason()}); + } + else { + promise.emplace_value(count); + } + }); + return pf.future.get() >= expected_size; + }, + std::chrono::minutes(15), std::chrono::milliseconds(500)); +} + void trigger_client_reset(const AppSession& app_session) { // cause a client reset by restarting the sync service diff --git a/test/object-store/sync/sync_test_utils.hpp b/test/object-store/sync/sync_test_utils.hpp index 52805dfa1d8..7686f6cea17 100644 --- a/test/object-store/sync/sync_test_utils.hpp +++ b/test/object-store/sync/sync_test_utils.hpp @@ -217,6 +217,9 @@ std::unique_ptr make_baas_flx_client_reset(const Realm::Config& void wait_for_object_to_persist_to_atlas(std::shared_ptr user, const AppSession& app_session, const std::string& schema_name, const bson::BsonDocument& filter_bson); +void wait_for_num_objects_in_atlas(std::shared_ptr user, const AppSession& app_session, + const std::string& schema_name, size_t expected_size); + void trigger_client_reset(const AppSession& app_session); void trigger_client_reset(const AppSession& app_session, const SharedRealm& realm); #endif // REALM_ENABLE_AUTH_TESTS