mirror of
https://github.com/ppy/osu.git
synced 2024-09-21 20:47:28 +08:00
Fix transaction not being disposed
This commit is contained in:
parent
5197d0fa9e
commit
ac216d94a8
@ -59,6 +59,24 @@ namespace osu.Game.Tests.Database
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestFailedWritePerformsRollback()
|
||||
{
|
||||
RunTestWithRealm((realm, _) =>
|
||||
{
|
||||
Assert.Throws<InvalidOperationException>(() =>
|
||||
{
|
||||
realm.Write(r =>
|
||||
{
|
||||
r.Add(new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata()));
|
||||
throw new InvalidOperationException();
|
||||
});
|
||||
});
|
||||
|
||||
Assert.That(realm.Run(r => r.All<BeatmapInfo>()), Is.Empty);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestNestedWriteCalls()
|
||||
{
|
||||
|
@ -20,6 +20,8 @@ namespace osu.Game.Database
|
||||
{
|
||||
Transaction? transaction = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (!realm.IsInTransaction)
|
||||
transaction = realm.BeginWrite();
|
||||
|
||||
@ -27,6 +29,11 @@ namespace osu.Game.Database
|
||||
|
||||
transaction?.Commit();
|
||||
}
|
||||
finally
|
||||
{
|
||||
transaction?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Perform a write operation against the provided realm instance.
|
||||
@ -40,6 +47,8 @@ namespace osu.Game.Database
|
||||
{
|
||||
Transaction? transaction = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (!realm.IsInTransaction)
|
||||
transaction = realm.BeginWrite();
|
||||
|
||||
@ -49,6 +58,11 @@ namespace osu.Game.Database
|
||||
|
||||
return result;
|
||||
}
|
||||
finally
|
||||
{
|
||||
transaction?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the provided change set has changes to the top level collection.
|
||||
|
Loading…
Reference in New Issue
Block a user