Skip to content

Commit

Permalink
Validate that deleting an in-memory realm does not throw if properly …
Browse files Browse the repository at this point in the history
…disposed. (#3043)

* Add test for deleting realm w/ frozen objects.

* Add CHANGELOG entry.

* Add test for deleting regular realm w/ frozen objects.
  • Loading branch information
elle-j authored Oct 6, 2022
1 parent fe36a62 commit 9552ed3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Tests/Realm.Tests/Database/InMemoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,25 @@ public void InMemoryRealm_WhenEncrypted_Throws()
EncryptionKey = TestHelpers.GetEncryptionKey(23)
});
}

[Test]
public void InMemoryRealmWithFrozenObjects_WhenDeleted_DoesNotThrow()
{
var realm = GetRealm(_config);
var frozenObj = realm.Write(() =>
{
return realm.Add(new IntPropertyObject
{
Int = 1
}).Freeze();
});

frozenObj.Realm.Dispose();
realm.Dispose();

Assert.That(frozenObj.Realm.IsClosed, Is.True);
Assert.That(realm.IsClosed, Is.True);
Assert.DoesNotThrow(() => Realm.DeleteRealm(_config));
}
}
}
21 changes: 21 additions & 0 deletions Tests/Realm.Tests/Database/InstanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,27 @@ public void GetInstance_WithSchema_MixingManualAndTyped_ReturnsCorrectObjectClas
Assert.That(allFoos.Count(), Is.EqualTo(0));
}

[Test]
public void RealmWithFrozenObjects_WhenDeleted_DoesNotThrow()
{
var config = new RealmConfiguration(Guid.NewGuid().ToString());
var realm = GetRealm(config);
var frozenObj = realm.Write(() =>
{
return realm.Add(new IntPropertyObject
{
Int = 1
}).Freeze();
});

frozenObj.Realm.Dispose();
realm.Dispose();

Assert.That(frozenObj.Realm.IsClosed, Is.True);
Assert.That(realm.IsClosed, Is.True);
Assert.DoesNotThrow(() => Realm.DeleteRealm(config));
}

private const int DummyDataSize = 200;

private static void AddDummyData(Realm realm)
Expand Down

0 comments on commit 9552ed3

Please sign in to comment.