mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 10:12:54 +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,12 +20,19 @@ namespace osu.Game.Database
|
||||
{
|
||||
Transaction? transaction = null;
|
||||
|
||||
if (!realm.IsInTransaction)
|
||||
transaction = realm.BeginWrite();
|
||||
try
|
||||
{
|
||||
if (!realm.IsInTransaction)
|
||||
transaction = realm.BeginWrite();
|
||||
|
||||
function(realm);
|
||||
function(realm);
|
||||
|
||||
transaction?.Commit();
|
||||
transaction?.Commit();
|
||||
}
|
||||
finally
|
||||
{
|
||||
transaction?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -40,14 +47,21 @@ namespace osu.Game.Database
|
||||
{
|
||||
Transaction? transaction = null;
|
||||
|
||||
if (!realm.IsInTransaction)
|
||||
transaction = realm.BeginWrite();
|
||||
try
|
||||
{
|
||||
if (!realm.IsInTransaction)
|
||||
transaction = realm.BeginWrite();
|
||||
|
||||
var result = function(realm);
|
||||
var result = function(realm);
|
||||
|
||||
transaction?.Commit();
|
||||
transaction?.Commit();
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
finally
|
||||
{
|
||||
transaction?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Loading…
Reference in New Issue
Block a user