Skip to content

Commit

Permalink
Try solve hanging tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
leemaguire committed Nov 20, 2023
1 parent 91b70a2 commit c92a24c
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 104 deletions.
45 changes: 23 additions & 22 deletions tests/experimental/sync/asymmetric_object_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,32 @@

using namespace realm;

TEST_CASE("asymmetric object", "[sync_beta]") {
Admin::Session test_session = Admin::Session::make_default_session();

SECTION("basic asymmetric object", "[sync]") {
std::cout << "start basic" << "\n";
auto asymmetric_app_id = test_session.create_app({}, "test", true);
auto app = realm::App(realm::App::configuration({asymmetric_app_id, test_session.base_url()}));
auto user = app.login(realm::App::credentials::anonymous()).get();
auto synced_realm = experimental::open<experimental::AllTypesAsymmetricObject, experimental::EmbeddedFoo>(user.flexible_sync_configuration());

auto obj = experimental::AllTypesAsymmetricObject();
const realm::object_id oid = realm::object_id::generate();
obj._id = oid;
synced_realm.write([&] {
synced_realm.add(std::move(obj));
});

test::wait_for_sync_uploads(user).get();
test::wait_for_sync_downloads(user).get();

//TEST_CASE("asymmetric object", "[sync_beta]") {
// Admin::Session test_session = Admin::Session::make_default_session();
//
// SECTION("basic asymmetric object", "[sync]") {
// std::cout << "start basic" << "\n";
// auto asymmetric_app_id = test_session.create_app({}, "test", true);
// auto app = realm::App(realm::App::configuration({asymmetric_app_id, test_session.base_url()}));
// auto user = app.login(realm::App::credentials::anonymous()).get();
// auto synced_realm = experimental::open<experimental::AllTypesAsymmetricObject, experimental::EmbeddedFoo>(user.flexible_sync_configuration());
//
// auto obj = experimental::AllTypesAsymmetricObject();
// const realm::object_id oid = realm::object_id::generate();
// obj._id = oid;
// //Getting error "sync error: Client attempted a write that is not allowed" on CI here
// synced_realm.write([&] {
// synced_realm.add(std::move(obj));
// });
//
// test::wait_for_sync_uploads(user).get();
// test::wait_for_sync_downloads(user).get();
//
// auto result = user.call_function("asymmetricSyncData", bson::BsonArray({bson::BsonDocument{{"_id", oid.to_string()}}})).get();
// CHECK(result);
// auto arr = bson::BsonArray(*result);
// CHECK(arr.size() == 1);
// CHECK(bson::BsonDocument(arr[0])["_id"].operator ObjectId().to_string() == oid.to_string());
// std::cout << "end asymmetric object" << "\n";
}
}
// }
//}
164 changes: 82 additions & 82 deletions tests/experimental/sync/flexible_sync_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,85 +109,85 @@ TEST_CASE("flexible_sync_beta", "[sync]") {
// }
}

//template<typename T, typename Func>
//void test_set(realm::experimental::managed<T>* property, Func f,
// std::vector<typename T::value_type>&& values, size_t&& expected_count = 3) {
// f(property, values, expected_count);
//}
//
//TEST_CASE("set collection sync", "[set]") {
// Admin::Session test_session = Admin::Session::make_default_session();
// auto app = realm::App(realm::App::configuration({test_session.cached_app_id(), test_session.base_url()}));
//
// SECTION("insert") {
// std::cout << "start insert" << "\n";
// auto user = app.login(realm::App::credentials::anonymous()).get();
// auto flx_sync_config = user.flexible_sync_configuration();
// auto realm = realm::experimental::db(std::move(flx_sync_config));
// auto update_success = realm.subscriptions().update([](realm::mutable_sync_subscription_set &subs) {
// subs.clear();
// }).get();
// CHECK(update_success == true);
// CHECK(realm.subscriptions().size() == 0);
//
// update_success = realm.subscriptions().update([](realm::mutable_sync_subscription_set &subs) {
// subs.add<experimental::AllTypesObject>("foo-strings");
// subs.add<experimental::AllTypesObjectLink>("foo-link");
// }).get();
// CHECK(update_success == true);
// CHECK(realm.subscriptions().size() == 2);
//
// auto obj = realm::experimental::AllTypesObject();
//
// auto managed_obj = realm.write([&]() {
// return realm.add(std::move(obj));
// });
//
// auto scenario = [&](auto &p, auto &values, size_t expected_count) {
// realm.write([&]() {
// for (auto v: values) {
// p->insert(v);
// }
// });
// CHECK(p->size() == expected_count);
// };
//
// test_set(&managed_obj.set_int_col, scenario, {42, 42, 24, -1});
// test_set(&managed_obj.set_double_col, scenario, {42.001, 42.001, 24.001, -1.001});
// test_set(&managed_obj.set_bool_col, scenario, {true, false, true}, 2);
// test_set(&managed_obj.set_str_col, scenario, {"42", "42", "24", "-1"});
// test_set(&managed_obj.set_uuid_col, scenario, {realm::uuid("18de7916-7f84-11ec-a8a3-0242ac120000"), realm::uuid("18de7916-7f84-11ec-a8a3-0242ac120000"), realm::uuid("18de7916-7f84-11ec-a8a3-0242ac120001"), realm::uuid("18de7916-7f84-11ec-a8a3-0242ac120002")});
// auto obj_id = realm::object_id::generate();
// test_set(&managed_obj.set_object_id_col, scenario, {obj_id, obj_id, realm::object_id::generate(), realm::object_id::generate()});
//
// auto bin_data = std::vector<uint8_t>({1, 2, 3, 4});
// test_set(&managed_obj.set_binary_col, scenario, {bin_data, bin_data, std::vector<uint8_t>({1, 3, 4}), std::vector<uint8_t>({1})});
//
// auto time = std::chrono::system_clock::now();
// auto time2 = time + time.time_since_epoch();
// test_set(&managed_obj.set_date_col, scenario, {time, time, time2, std::chrono::time_point<std::chrono::system_clock>()});
// test_set(&managed_obj.set_mixed_col, scenario, {realm::mixed((int64_t)42), realm::mixed((int64_t)42), realm::mixed("24"), realm::mixed(realm::uuid("18de7916-7f84-11ec-a8a3-0242ac120002"))});
//
// test::wait_for_sync_uploads(user).get();
// test::wait_for_sync_downloads(user).get();
//
// app.register_user("[email protected]", "foobar").get();
// auto user2 = app.login(realm::App::credentials::username_password("[email protected]", "foobar")).get();
//
// auto realm2 = realm::experimental::db(user2.flexible_sync_configuration());
// auto update_success2 = realm2.subscriptions().update([](realm::mutable_sync_subscription_set &subs) {
// subs.add<experimental::AllTypesObject>("foo-strings", [](auto &obj) {
// return obj.str_col == "foo";
// });
// subs.add<experimental::AllTypesObjectLink>("foo-link");
// }).get();
// CHECK(update_success2 == true);
// CHECK(realm2.subscriptions().size() == 2);
// test::wait_for_sync_downloads(user2).get();
// realm2.refresh();
// auto objs = realm2.objects<experimental::AllTypesObject>();
// CHECK(objs.size() == 1);
// std::cout << "end insert" << "\n";
//
// }
//}
template<typename T, typename Func>
void test_set(realm::experimental::managed<T>* property, Func f,
std::vector<typename T::value_type>&& values, size_t&& expected_count = 3) {
f(property, values, expected_count);
}

TEST_CASE("set collection sync", "[set]") {
Admin::Session test_session = Admin::Session::make_default_session();
auto app = realm::App(realm::App::configuration({test_session.cached_app_id(), test_session.base_url()}));

SECTION("insert") {
std::cout << "start insert" << "\n";
auto user = app.login(realm::App::credentials::anonymous()).get();
auto flx_sync_config = user.flexible_sync_configuration();
auto realm = realm::experimental::db(std::move(flx_sync_config));
auto update_success = realm.subscriptions().update([](realm::mutable_sync_subscription_set &subs) {
subs.clear();
}).get();
CHECK(update_success == true);
CHECK(realm.subscriptions().size() == 0);

update_success = realm.subscriptions().update([](realm::mutable_sync_subscription_set &subs) {
subs.add<experimental::AllTypesObject>("foo-strings");
subs.add<experimental::AllTypesObjectLink>("foo-link");
}).get();
CHECK(update_success == true);
CHECK(realm.subscriptions().size() == 2);

auto obj = realm::experimental::AllTypesObject();

auto managed_obj = realm.write([&]() {
return realm.add(std::move(obj));
});

auto scenario = [&](auto &p, auto &values, size_t expected_count) {
realm.write([&]() {
for (auto v: values) {
p->insert(v);
}
});
CHECK(p->size() == expected_count);
};

test_set(&managed_obj.set_int_col, scenario, {42, 42, 24, -1});
test_set(&managed_obj.set_double_col, scenario, {42.001, 42.001, 24.001, -1.001});
test_set(&managed_obj.set_bool_col, scenario, {true, false, true}, 2);
test_set(&managed_obj.set_str_col, scenario, {"42", "42", "24", "-1"});
test_set(&managed_obj.set_uuid_col, scenario, {realm::uuid("18de7916-7f84-11ec-a8a3-0242ac120000"), realm::uuid("18de7916-7f84-11ec-a8a3-0242ac120000"), realm::uuid("18de7916-7f84-11ec-a8a3-0242ac120001"), realm::uuid("18de7916-7f84-11ec-a8a3-0242ac120002")});
auto obj_id = realm::object_id::generate();
test_set(&managed_obj.set_object_id_col, scenario, {obj_id, obj_id, realm::object_id::generate(), realm::object_id::generate()});

auto bin_data = std::vector<uint8_t>({1, 2, 3, 4});
test_set(&managed_obj.set_binary_col, scenario, {bin_data, bin_data, std::vector<uint8_t>({1, 3, 4}), std::vector<uint8_t>({1})});

auto time = std::chrono::system_clock::now();
auto time2 = time + time.time_since_epoch();
test_set(&managed_obj.set_date_col, scenario, {time, time, time2, std::chrono::time_point<std::chrono::system_clock>()});
test_set(&managed_obj.set_mixed_col, scenario, {realm::mixed((int64_t)42), realm::mixed((int64_t)42), realm::mixed("24"), realm::mixed(realm::uuid("18de7916-7f84-11ec-a8a3-0242ac120002"))});

test::wait_for_sync_uploads(user).get();
test::wait_for_sync_downloads(user).get();

app.register_user("[email protected]", "foobar").get();
auto user2 = app.login(realm::App::credentials::username_password("[email protected]", "foobar")).get();

auto realm2 = realm::experimental::db(user2.flexible_sync_configuration());
auto update_success2 = realm2.subscriptions().update([](realm::mutable_sync_subscription_set &subs) {
subs.add<experimental::AllTypesObject>("foo-strings", [](auto &obj) {
return obj.str_col == "foo";
});
subs.add<experimental::AllTypesObjectLink>("foo-link");
}).get();
CHECK(update_success2 == true);
CHECK(realm2.subscriptions().size() == 2);
test::wait_for_sync_downloads(user2).get();
realm2.refresh();
auto objs = realm2.objects<experimental::AllTypesObject>();
CHECK(objs.size() == 1);
std::cout << "end insert" << "\n";

}
}

0 comments on commit c92a24c

Please sign in to comment.