diff --git a/osu.Game.Tests/Collections/IO/ImportCollectionsTest.cs b/osu.Game.Tests/Collections/IO/ImportCollectionsTest.cs
index c31aafa67f..9a8f29647d 100644
--- a/osu.Game.Tests/Collections/IO/ImportCollectionsTest.cs
+++ b/osu.Game.Tests/Collections/IO/ImportCollectionsTest.cs
@@ -138,7 +138,7 @@ namespace osu.Game.Tests.Collections.IO
{
string firstRunName;
- using (var host = new CleanRunHeadlessGameHost(bypassCleanup: true))
+ using (var host = new CleanRunHeadlessGameHost(bypassCleanupOnDispose: true))
{
firstRunName = host.Name;
diff --git a/osu.Game.Tests/NonVisual/CustomDataDirectoryTest.cs b/osu.Game.Tests/NonVisual/CustomDataDirectoryTest.cs
index 216bd0fd3c..216db2121c 100644
--- a/osu.Game.Tests/NonVisual/CustomDataDirectoryTest.cs
+++ b/osu.Game.Tests/NonVisual/CustomDataDirectoryTest.cs
@@ -315,6 +315,26 @@ namespace osu.Game.Tests.NonVisual
}
}
+ [Test]
+ public void TestBackupCreatedOnCorruptRealm()
+ {
+ using (var host = new CustomTestHeadlessGameHost())
+ {
+ try
+ {
+ File.WriteAllText(host.InitialStorage.GetFullPath(OsuGameBase.CLIENT_DATABASE_FILENAME, true), "i am definitely not a realm file");
+
+ LoadOsuIntoHost(host);
+
+ Assert.That(host.InitialStorage.GetFiles(string.Empty, "*_corrupt.realm"), Has.One.Items);
+ }
+ finally
+ {
+ host.Exit();
+ }
+ }
+ }
+
private static string getDefaultLocationFor(CustomTestHeadlessGameHost host)
{
string path = Path.Combine(TestRunHeadlessGameHost.TemporaryTestDirectory, host.Name);
@@ -347,7 +367,7 @@ namespace osu.Game.Tests.NonVisual
public Storage InitialStorage { get; }
public CustomTestHeadlessGameHost([CallerMemberName] string callingMethodName = @"")
- : base(callingMethodName: callingMethodName)
+ : base(callingMethodName: callingMethodName, bypassCleanupOnSetup: true)
{
string defaultStorageLocation = getDefaultLocationFor(this);
diff --git a/osu.Game/Tests/CleanRunHeadlessGameHost.cs b/osu.Game/Tests/CleanRunHeadlessGameHost.cs
index d36168d3dd..02d67de5a5 100644
--- a/osu.Game/Tests/CleanRunHeadlessGameHost.cs
+++ b/osu.Game/Tests/CleanRunHeadlessGameHost.cs
@@ -15,30 +15,38 @@ namespace osu.Game.Tests
///
public class CleanRunHeadlessGameHost : TestRunHeadlessGameHost
{
+ private readonly bool bypassCleanupOnSetup;
+
///
/// Create a new instance.
///
/// Whether to bind IPC channels.
/// Whether the host should be forced to run in realtime, rather than accelerated test time.
- /// Whether to bypass directory cleanup on host disposal. Should be used only if a subsequent test relies on the files still existing.
+ /// Whether to bypass directory cleanup on .
+ /// Whether to bypass directory cleanup on host disposal. Should be used only if a subsequent test relies on the files still existing.
/// The name of the calling method, used for test file isolation and clean-up.
- public CleanRunHeadlessGameHost(bool bindIPC = false, bool realtime = true, bool bypassCleanup = false, [CallerMemberName] string callingMethodName = @"")
+ public CleanRunHeadlessGameHost(bool bindIPC = false, bool realtime = true, bool bypassCleanupOnSetup = false, bool bypassCleanupOnDispose = false,
+ [CallerMemberName] string callingMethodName = @"")
: base($"{callingMethodName}-{Guid.NewGuid()}", new HostOptions
{
BindIPC = bindIPC,
- }, bypassCleanup: bypassCleanup, realtime: realtime)
+ }, bypassCleanup: bypassCleanupOnDispose, realtime: realtime)
{
+ this.bypassCleanupOnSetup = bypassCleanupOnSetup;
}
protected override void SetupForRun()
{
- try
+ if (!bypassCleanupOnSetup)
{
- Storage.DeleteDirectory(string.Empty);
- }
- catch
- {
- // May fail if a logging target has already been set via OsuStorage.ChangeTargetStorage.
+ try
+ {
+ Storage.DeleteDirectory(string.Empty);
+ }
+ catch
+ {
+ // May fail if a logging target has already been set via OsuStorage.ChangeTargetStorage.
+ }
}
// base call needs to be run *after* storage is emptied, as it updates the (static) logger's storage and may start writing