Skip to content

Commit

Permalink
maybe fix a race in a test (#6651)
Browse files Browse the repository at this point in the history
  • Loading branch information
ironage authored May 23, 2023
1 parent cb9b80b commit dcf925e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions test/object-store/sync/flx_sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
26 changes: 26 additions & 0 deletions test/object-store/sync/sync_test_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,32 @@ void wait_for_object_to_persist_to_atlas(std::shared_ptr<SyncUser> user, const A
std::chrono::minutes(15), std::chrono::milliseconds(500));
}

void wait_for_num_objects_in_atlas(std::shared_ptr<SyncUser> 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<uint64_t>();
object_coll.count(filter_bson, [promise = std::move(pf.promise)](
uint64_t count, util::Optional<app::AppError> 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
Expand Down
3 changes: 3 additions & 0 deletions test/object-store/sync/sync_test_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ std::unique_ptr<TestClientReset> make_baas_flx_client_reset(const Realm::Config&
void wait_for_object_to_persist_to_atlas(std::shared_ptr<SyncUser> 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<SyncUser> 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
Expand Down

0 comments on commit dcf925e

Please sign in to comment.