mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 16:32:54 +08:00
Merge pull request #18951 from peppy/fix-realm-missing-transaction-rollback
Fix `PerformWrite` not rolling back transaction on exception
This commit is contained in:
commit
5a346edc63
@ -91,6 +91,25 @@ namespace osu.Game.Tests.Database
|
||||
Assert.IsFalse(liveBeatmap.PerformRead(l => l.Hidden));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestTransactionRolledBackOnException()
|
||||
{
|
||||
RunTestWithRealm((realm, _) =>
|
||||
{
|
||||
var beatmap = new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata());
|
||||
|
||||
realm.Run(r => r.Write(_ => r.Add(beatmap)));
|
||||
|
||||
var liveBeatmap = beatmap.ToLive(realm);
|
||||
|
||||
Assert.Throws<InvalidOperationException>(() => liveBeatmap.PerformWrite(l => throw new InvalidOperationException()));
|
||||
Assert.IsFalse(liveBeatmap.PerformRead(l => l.Hidden));
|
||||
|
||||
liveBeatmap.PerformWrite(l => l.Hidden = true);
|
||||
Assert.IsTrue(liveBeatmap.PerformRead(l => l.Hidden));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestScopedReadWithoutContext()
|
||||
{
|
||||
|
@ -104,9 +104,12 @@ namespace osu.Game.Database
|
||||
|
||||
PerformRead(t =>
|
||||
{
|
||||
var transaction = t.Realm.BeginWrite();
|
||||
perform(t);
|
||||
transaction.Commit();
|
||||
using (var transaction = t.Realm.BeginWrite())
|
||||
{
|
||||
perform(t);
|
||||
transaction.Commit();
|
||||
}
|
||||
|
||||
RealmLiveStatistics.WRITES.Value++;
|
||||
});
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Database;
|
||||
@ -19,8 +20,8 @@ namespace osu.Game.Models
|
||||
|
||||
public RealmNamedFileUsage(RealmFile file, string filename)
|
||||
{
|
||||
File = file;
|
||||
Filename = filename;
|
||||
File = file ?? throw new ArgumentNullException(nameof(file));
|
||||
Filename = filename ?? throw new ArgumentNullException(nameof(filename));
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
|
Loading…
Reference in New Issue
Block a user