Skip to content

Commit

Permalink
Reenable CollectionMerge test (#3637)
Browse files Browse the repository at this point in the history
  • Loading branch information
nirinchev authored Jul 4, 2024
1 parent ed4b790 commit b800ad7
Showing 1 changed file with 17 additions and 40 deletions.
57 changes: 17 additions & 40 deletions Tests/Realm.Tests/Sync/DataTypeSynchronizationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,7 @@ private void TestListCore<T>(Func<SyncCollectionsObject, IList<T>> getter, T ite
var realm1 = await GetIntegrationRealmAsync(partition);
var realm2 = await GetIntegrationRealmAsync(partition);
var obj1 = realm1.Write(() =>
{
return realm1.Add(new SyncCollectionsObject());
});
var obj1 = realm1.Write(() => realm1.Add(new SyncCollectionsObject()));
var obj2 = await WaitForObjectAsync(obj1, realm2);
Expand Down Expand Up @@ -423,10 +420,7 @@ private void TestSetCore<T>(Func<SyncCollectionsObject, ISet<T>> getter, T item1
var realm1 = await GetIntegrationRealmAsync(partition);
var realm2 = await GetIntegrationRealmAsync(partition);
var obj1 = realm1.Write(() =>
{
return realm1.Add(new SyncCollectionsObject());
});
var obj1 = realm1.Write(() => realm1.Add(new SyncCollectionsObject()));
var obj2 = await WaitForObjectAsync(obj1, realm2);
Expand Down Expand Up @@ -471,21 +465,16 @@ private void TestSetCore<T>(Func<SyncCollectionsObject, ISet<T>> getter, T item1

private void TestDictionaryCore<T>(Func<SyncCollectionsObject, IDictionary<string, T>> getter, T item1, T item2, Func<T, T, bool>? equalsOverride = null)
{
var comparer = new Func<KeyValuePair<string, T>, KeyValuePair<string, T>, bool>((a, b) =>
{
return a.Key == b.Key && (equalsOverride?.Invoke(a.Value, b.Value) ?? a.Value?.Equals(b.Value) == true);
});
Func<KeyValuePair<string, T>, KeyValuePair<string, T>, bool> comparer =
(a, b) => a.Key == b.Key && (equalsOverride?.Invoke(a.Value, b.Value) ?? a.Value?.Equals(b.Value) == true);

SyncTestHelpers.RunBaasTestAsync(async () =>
{
var partition = Guid.NewGuid().ToString();
var realm1 = await GetIntegrationRealmAsync(partition);
var realm2 = await GetIntegrationRealmAsync(partition);
var obj1 = realm1.Write(() =>
{
return realm1.Add(new SyncCollectionsObject());
});
var obj1 = realm1.Write(() => realm1.Add(new SyncCollectionsObject()));
var obj2 = await WaitForObjectAsync(obj1, realm2, "initial obj from 1 shows up in 2");
Expand Down Expand Up @@ -562,10 +551,7 @@ private void TestPropertyCore<T>(Func<SyncAllTypesObject, T> getter, Action<Sync
realm2.Subscriptions.Add(realm2.All<IntPropertyObject>());
});
var obj1 = realm1.Write(() =>
{
return realm1.Add(new SyncAllTypesObject());
});
var obj1 = realm1.Write(() => realm1.Add(new SyncAllTypesObject()));
var obj2 = await WaitForObjectAsync(obj1, realm2);
Expand Down Expand Up @@ -598,7 +584,7 @@ private void TestPropertyCore<T>(Func<SyncAllTypesObject, T> getter, Action<Sync
}

[Test]
public void Bootstrap()
public void NestedCollections_Bootstrap()
{
SyncTestHelpers.RunBaasTestAsync(async () =>
{
Expand Down Expand Up @@ -670,7 +656,7 @@ await TestHelpers.WaitForConditionAsync(() => realm2.FindCore<IntPropertyObject>
});
}

public static readonly IList<RealmValue> RealmValueCollectionTestValues = new List<RealmValue>()
private static readonly RealmValue[] RealmValueCollectionTestValues =
{
"abc",
new ObjectId("5f63e882536de46d71877979"),
Expand Down Expand Up @@ -730,7 +716,7 @@ await TestHelpers.WaitForConditionAsync(() => realm2.FindCore<IntPropertyObject>
};

[Test]
public void ListManipulations()
public void NestedCollections_ListManipulations()
{
SyncTestHelpers.RunBaasTestAsync(async () =>
{
Expand Down Expand Up @@ -765,7 +751,7 @@ public void ListManipulations()
}
// Remove elements one by one and verify that changes are synced
for (int index = 0; index < RealmValueCollectionTestValues.Count; index++)
for (var i = 0; i < RealmValueCollectionTestValues.Length; i++)
{
realm1.Write(() =>
{
Expand Down Expand Up @@ -804,7 +790,7 @@ public void ListManipulations()
}

[Test]
public void DictionaryManipulations()
public void NestedCollections_DictionaryManipulations()
{
SyncTestHelpers.RunBaasTestAsync(async () =>
{
Expand Down Expand Up @@ -854,8 +840,7 @@ public void DictionaryManipulations()
}

[Test]
[Ignore("Crashes until https://github.com/realm/realm-core/issues/7488 is fixed")]
public void CollectionMerge()
public void NestedCollections_Merge()
{
SyncTestHelpers.RunBaasTestAsync(async () =>
{
Expand Down Expand Up @@ -942,7 +927,7 @@ private static RealmValue Clone(RealmValue original)
var robj = original.AsIRealmObject();
var clone = (IRealmObjectBase)Activator.CreateInstance(robj.GetType())!;
var properties = robj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)
.Where(p => p.CanWrite && p.CanRead && !p.HasCustomAttribute<PrimaryKeyAttribute>());
.Where(p => p is { CanWrite: true, CanRead: true } && !p.HasCustomAttribute<PrimaryKeyAttribute>());

foreach (var prop in properties)
{
Expand Down Expand Up @@ -970,7 +955,7 @@ private static T CloneOrLookup<T>(T value, Realm targetRealm)
}

// If RealmValue that is holding an object, call CloneOrLookup
if (value is RealmValue rvalue && rvalue.Type == RealmValueType.Object)
if (value is RealmValue { Type: RealmValueType.Object } rvalue)
{
var cloned = CloneOrLookup(rvalue.AsIRealmObject(), targetRealm);
return Operator.Convert<IRealmObjectBase, T>(cloned);
Expand Down Expand Up @@ -1000,15 +985,9 @@ private static bool RealmValueEquals(RealmValue a, RealmValue b)
return false;
}

foreach (var prop in objA.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(o => o.CanWrite && o.CanRead))
{
if (prop.GetValue(objA)?.Equals(prop.GetValue(objB)) != true)
{
return false;
}
}

return true;
return objA.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)
.Where(o => o is { CanWrite: true, CanRead: true })
.All(prop => prop.GetValue(objA)?.Equals(prop.GetValue(objB)) == true);
}

private static async Task WaitForPropertyChangedAsync(IRealmObject realmObject, int timeout = 10 * 1000)
Expand All @@ -1030,8 +1009,6 @@ void RealmObject_PropertyChanged(object? sender, PropertyChangedEventArgs? e)

private static async Task WaitForCollectionAsync<T>(IEnumerable<T> first, IEnumerable<T> second, Func<T, T, bool> comparer, string message)
{
comparer ??= EqualityComparer<T>.Default.Equals;

await TestHelpers.WaitForConditionAsync(() => IsEquivalent(first, second, comparer), errorMessage: message);
Assert.That(first, Is.EquivalentTo(second).Using(comparer));
}
Expand Down

0 comments on commit b800ad7

Please sign in to comment.