mirror of
https://github.com/ppy/osu.git
synced 2025-01-21 08:12:56 +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]
|
[Test]
|
||||||
public void TestNestedWriteCalls()
|
public void TestNestedWriteCalls()
|
||||||
{
|
{
|
||||||
|
@ -20,12 +20,19 @@ namespace osu.Game.Database
|
|||||||
{
|
{
|
||||||
Transaction? transaction = null;
|
Transaction? transaction = null;
|
||||||
|
|
||||||
if (!realm.IsInTransaction)
|
try
|
||||||
transaction = realm.BeginWrite();
|
{
|
||||||
|
if (!realm.IsInTransaction)
|
||||||
|
transaction = realm.BeginWrite();
|
||||||
|
|
||||||
function(realm);
|
function(realm);
|
||||||
|
|
||||||
transaction?.Commit();
|
transaction?.Commit();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
transaction?.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -40,14 +47,21 @@ namespace osu.Game.Database
|
|||||||
{
|
{
|
||||||
Transaction? transaction = null;
|
Transaction? transaction = null;
|
||||||
|
|
||||||
if (!realm.IsInTransaction)
|
try
|
||||||
transaction = realm.BeginWrite();
|
{
|
||||||
|
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>
|
/// <summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user