Ensure exception is only thrown once on rollback

This commit is contained in:
Dean Herbert 2019-06-10 18:13:33 +09:00
parent dcdb806120
commit 28b2a516e3
1 changed files with 17 additions and 7 deletions

View File

@ -11,6 +11,7 @@
using osu.Framework.Platform;
using osu.Game.IPC;
using osu.Framework.Allocation;
using osu.Framework.Logging;
using osu.Game.Beatmaps;
using osu.Game.IO;
using osu.Game.Tests.Resources;
@ -96,24 +97,31 @@ public async Task TestRollbackOnFailure()
{
try
{
int itemAddRemoveFireCount = 0;
int loggedExceptionCount = 0;
Logger.NewEntry += l =>
{
if (l.Target == LoggingTarget.Database && l.Exception != null)
Interlocked.Increment(ref loggedExceptionCount);
};
var osu = loadOsu(host);
var manager = osu.Dependencies.Get<BeatmapManager>();
var files = osu.Dependencies.Get<FileStore>();
int fireCount = 0;
// ReSharper disable once AccessToModifiedClosure
manager.ItemAdded += (_, __) => fireCount++;
manager.ItemRemoved += _ => fireCount++;
manager.ItemAdded += (_, __) => Interlocked.Increment(ref itemAddRemoveFireCount);
manager.ItemRemoved += _ => Interlocked.Increment(ref itemAddRemoveFireCount);
var imported = await LoadOszIntoOsu(osu);
Assert.AreEqual(0, fireCount -= 1);
Assert.AreEqual(0, itemAddRemoveFireCount -= 1);
imported.Hash += "-changed";
manager.Update(imported);
Assert.AreEqual(0, fireCount -= 2);
Assert.AreEqual(0, itemAddRemoveFireCount -= 2);
Assert.AreEqual(1, manager.GetAllUsableBeatmapSets().Count);
Assert.AreEqual(1, manager.QueryBeatmapSets(_ => true).ToList().Count);
@ -145,7 +153,7 @@ public async Task TestRollbackOnFailure()
}
// no events should be fired in the case of a rollback.
Assert.AreEqual(0, fireCount);
Assert.AreEqual(0, itemAddRemoveFireCount);
Assert.AreEqual(1, manager.GetAllUsableBeatmapSets().Count);
Assert.AreEqual(1, manager.QueryBeatmapSets(_ => true).ToList().Count);
@ -153,6 +161,8 @@ public async Task TestRollbackOnFailure()
Assert.AreEqual(18, files.QueryFiles(_ => true).Count());
Assert.AreEqual(18, files.QueryFiles(f => f.ReferenceCount == 1).Count());
Assert.AreEqual(1, loggedExceptionCount);
}
finally
{