mirror of
https://github.com/osukey/osukey.git
synced 2025-06-07 04:18:04 +09:00
Fix incorrect nested result retrieval in ImportBeatmapTest
This commit is contained in:
parent
73b40e6833
commit
f3e889d0f6
@ -93,7 +93,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
using (var stream = File.OpenRead(tempPath))
|
using (var stream = File.OpenRead(tempPath))
|
||||||
{
|
{
|
||||||
importedSet = await manager.Import(new ImportTask(stream, Path.GetFileName(tempPath)));
|
importedSet = await manager.Import(new ImportTask(stream, Path.GetFileName(tempPath)));
|
||||||
ensureLoaded(osu);
|
await ensureLoaded(osu);
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.IsTrue(File.Exists(tempPath), "Stream source file somehow went missing");
|
Assert.IsTrue(File.Exists(tempPath), "Stream source file somehow went missing");
|
||||||
@ -171,7 +171,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
|
|
||||||
var importedSecondTime = await osu.Dependencies.Get<BeatmapManager>().Import(new ImportTask(temp));
|
var importedSecondTime = await osu.Dependencies.Get<BeatmapManager>().Import(new ImportTask(temp));
|
||||||
|
|
||||||
ensureLoaded(osu);
|
await ensureLoaded(osu);
|
||||||
|
|
||||||
// but contents doesn't, so existing should still be used.
|
// but contents doesn't, so existing should still be used.
|
||||||
Assert.IsTrue(imported.ID == importedSecondTime.Value.ID);
|
Assert.IsTrue(imported.ID == importedSecondTime.Value.ID);
|
||||||
@ -225,7 +225,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
|
|
||||||
var importedSecondTime = await osu.Dependencies.Get<BeatmapManager>().Import(new ImportTask(temp));
|
var importedSecondTime = await osu.Dependencies.Get<BeatmapManager>().Import(new ImportTask(temp));
|
||||||
|
|
||||||
ensureLoaded(osu);
|
await ensureLoaded(osu);
|
||||||
|
|
||||||
// check the newly "imported" beatmap is not the original.
|
// check the newly "imported" beatmap is not the original.
|
||||||
Assert.IsTrue(imported.ID != importedSecondTime.Value.ID);
|
Assert.IsTrue(imported.ID != importedSecondTime.Value.ID);
|
||||||
@ -277,7 +277,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
|
|
||||||
var importedSecondTime = await osu.Dependencies.Get<BeatmapManager>().Import(new ImportTask(temp));
|
var importedSecondTime = await osu.Dependencies.Get<BeatmapManager>().Import(new ImportTask(temp));
|
||||||
|
|
||||||
ensureLoaded(osu);
|
await ensureLoaded(osu);
|
||||||
|
|
||||||
// check the newly "imported" beatmap is not the original.
|
// check the newly "imported" beatmap is not the original.
|
||||||
Assert.IsTrue(imported.ID != importedSecondTime.Value.ID);
|
Assert.IsTrue(imported.ID != importedSecondTime.Value.ID);
|
||||||
@ -328,7 +328,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
|
|
||||||
var importedSecondTime = await osu.Dependencies.Get<BeatmapManager>().Import(new ImportTask(temp));
|
var importedSecondTime = await osu.Dependencies.Get<BeatmapManager>().Import(new ImportTask(temp));
|
||||||
|
|
||||||
ensureLoaded(osu);
|
await ensureLoaded(osu);
|
||||||
|
|
||||||
// check the newly "imported" beatmap is not the original.
|
// check the newly "imported" beatmap is not the original.
|
||||||
Assert.IsTrue(imported.ID != importedSecondTime.Value.ID);
|
Assert.IsTrue(imported.ID != importedSecondTime.Value.ID);
|
||||||
@ -637,7 +637,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
if (!importer.ImportAsync(temp).Wait(10000))
|
if (!importer.ImportAsync(temp).Wait(10000))
|
||||||
Assert.Fail(@"IPC took too long to send");
|
Assert.Fail(@"IPC took too long to send");
|
||||||
|
|
||||||
ensureLoaded(osu);
|
ensureLoaded(osu).WaitSafely();
|
||||||
|
|
||||||
waitForOrAssert(() => !File.Exists(temp), "Temporary still exists after IPC import", 5000);
|
waitForOrAssert(() => !File.Exists(temp), "Temporary still exists after IPC import", 5000);
|
||||||
}
|
}
|
||||||
@ -659,7 +659,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
string temp = TestResources.GetTestBeatmapForImport();
|
string temp = TestResources.GetTestBeatmapForImport();
|
||||||
using (File.OpenRead(temp))
|
using (File.OpenRead(temp))
|
||||||
await osu.Dependencies.Get<BeatmapManager>().Import(temp);
|
await osu.Dependencies.Get<BeatmapManager>().Import(temp);
|
||||||
ensureLoaded(osu);
|
await ensureLoaded(osu);
|
||||||
File.Delete(temp);
|
File.Delete(temp);
|
||||||
Assert.IsFalse(File.Exists(temp), "We likely held a read lock on the file when we shouldn't");
|
Assert.IsFalse(File.Exists(temp), "We likely held a read lock on the file when we shouldn't");
|
||||||
}
|
}
|
||||||
@ -698,7 +698,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
|
|
||||||
await osu.Dependencies.Get<BeatmapManager>().Import(temp);
|
await osu.Dependencies.Get<BeatmapManager>().Import(temp);
|
||||||
|
|
||||||
ensureLoaded(osu);
|
await ensureLoaded(osu);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@ -741,7 +741,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
|
|
||||||
var imported = await osu.Dependencies.Get<BeatmapManager>().Import(new ImportTask(temp));
|
var imported = await osu.Dependencies.Get<BeatmapManager>().Import(new ImportTask(temp));
|
||||||
|
|
||||||
ensureLoaded(osu);
|
await ensureLoaded(osu);
|
||||||
|
|
||||||
Assert.IsFalse(imported.Value.Files.Any(f => f.Filename.Contains("subfolder")), "Files contain common subfolder");
|
Assert.IsFalse(imported.Value.Files.Any(f => f.Filename.Contains("subfolder")), "Files contain common subfolder");
|
||||||
}
|
}
|
||||||
@ -794,7 +794,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
|
|
||||||
var imported = await osu.Dependencies.Get<BeatmapManager>().Import(new ImportTask(temp));
|
var imported = await osu.Dependencies.Get<BeatmapManager>().Import(new ImportTask(temp));
|
||||||
|
|
||||||
ensureLoaded(osu);
|
await ensureLoaded(osu);
|
||||||
|
|
||||||
Assert.IsFalse(imported.Value.Files.Any(f => f.Filename.Contains("__MACOSX")), "Files contain resource fork folder, which should be ignored");
|
Assert.IsFalse(imported.Value.Files.Any(f => f.Filename.Contains("__MACOSX")), "Files contain resource fork folder, which should be ignored");
|
||||||
Assert.IsFalse(imported.Value.Files.Any(f => f.Filename.Contains("actual_data")), "Files contain common subfolder");
|
Assert.IsFalse(imported.Value.Files.Any(f => f.Filename.Contains("actual_data")), "Files contain common subfolder");
|
||||||
@ -812,7 +812,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public async Task TestUpdateBeatmapInfo()
|
public void TestUpdateBeatmapInfo()
|
||||||
{
|
{
|
||||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost())
|
using (HeadlessGameHost host = new CleanRunHeadlessGameHost())
|
||||||
{
|
{
|
||||||
@ -822,7 +822,8 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
var manager = osu.Dependencies.Get<BeatmapManager>();
|
var manager = osu.Dependencies.Get<BeatmapManager>();
|
||||||
|
|
||||||
string temp = TestResources.GetTestBeatmapForImport();
|
string temp = TestResources.GetTestBeatmapForImport();
|
||||||
await osu.Dependencies.Get<BeatmapManager>().Import(temp);
|
|
||||||
|
osu.Dependencies.Get<BeatmapManager>().Import(temp).WaitSafely();
|
||||||
|
|
||||||
// Update via the beatmap, not the beatmap info, to ensure correct linking
|
// Update via the beatmap, not the beatmap info, to ensure correct linking
|
||||||
BeatmapSetInfo setToUpdate = manager.GetAllUsableBeatmapSets()[0];
|
BeatmapSetInfo setToUpdate = manager.GetAllUsableBeatmapSets()[0];
|
||||||
@ -842,7 +843,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public async Task TestUpdateBeatmapFile()
|
public void TestUpdateBeatmapFile()
|
||||||
{
|
{
|
||||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost())
|
using (HeadlessGameHost host = new CleanRunHeadlessGameHost())
|
||||||
{
|
{
|
||||||
@ -852,7 +853,8 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
var manager = osu.Dependencies.Get<BeatmapManager>();
|
var manager = osu.Dependencies.Get<BeatmapManager>();
|
||||||
|
|
||||||
string temp = TestResources.GetTestBeatmapForImport();
|
string temp = TestResources.GetTestBeatmapForImport();
|
||||||
await osu.Dependencies.Get<BeatmapManager>().Import(temp);
|
|
||||||
|
osu.Dependencies.Get<BeatmapManager>().Import(temp).WaitSafely();
|
||||||
|
|
||||||
BeatmapSetInfo setToUpdate = manager.GetAllUsableBeatmapSets()[0];
|
BeatmapSetInfo setToUpdate = manager.GetAllUsableBeatmapSets()[0];
|
||||||
|
|
||||||
@ -976,35 +978,35 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<BeatmapSetInfo> LoadQuickOszIntoOsu(OsuGameBase osu)
|
public static Task<BeatmapSetInfo> LoadQuickOszIntoOsu(OsuGameBase osu) => Task.Factory.StartNew(() =>
|
||||||
{
|
{
|
||||||
string temp = TestResources.GetQuickTestBeatmapForImport();
|
string temp = TestResources.GetQuickTestBeatmapForImport();
|
||||||
|
|
||||||
var manager = osu.Dependencies.Get<BeatmapManager>();
|
var manager = osu.Dependencies.Get<BeatmapManager>();
|
||||||
|
|
||||||
var importedSet = await manager.Import(new ImportTask(temp)).ConfigureAwait(false);
|
var importedSet = manager.Import(new ImportTask(temp)).WaitSafelyForResult();
|
||||||
|
|
||||||
ensureLoaded(osu);
|
ensureLoaded(osu).WaitSafely();
|
||||||
|
|
||||||
waitForOrAssert(() => !File.Exists(temp), "Temporary file still exists after standard import", 5000);
|
waitForOrAssert(() => !File.Exists(temp), "Temporary file still exists after standard import", 5000);
|
||||||
|
|
||||||
return manager.GetAllUsableBeatmapSets().Find(beatmapSet => beatmapSet.ID == importedSet.Value.ID);
|
return manager.GetAllUsableBeatmapSets().Find(beatmapSet => beatmapSet.ID == importedSet.Value.ID);
|
||||||
}
|
}, TaskCreationOptions.LongRunning);
|
||||||
|
|
||||||
public static async Task<BeatmapSetInfo> LoadOszIntoOsu(OsuGameBase osu, string path = null, bool virtualTrack = false)
|
public static Task<BeatmapSetInfo> LoadOszIntoOsu(OsuGameBase osu, string path = null, bool virtualTrack = false) => Task.Factory.StartNew(() =>
|
||||||
{
|
{
|
||||||
string temp = path ?? TestResources.GetTestBeatmapForImport(virtualTrack);
|
string temp = path ?? TestResources.GetTestBeatmapForImport(virtualTrack);
|
||||||
|
|
||||||
var manager = osu.Dependencies.Get<BeatmapManager>();
|
var manager = osu.Dependencies.Get<BeatmapManager>();
|
||||||
|
|
||||||
var importedSet = await manager.Import(new ImportTask(temp)).ConfigureAwait(false);
|
var importedSet = manager.Import(new ImportTask(temp)).WaitSafelyForResult();
|
||||||
|
|
||||||
ensureLoaded(osu);
|
ensureLoaded(osu).WaitSafely();
|
||||||
|
|
||||||
waitForOrAssert(() => !File.Exists(temp), "Temporary file still exists after standard import", 5000);
|
waitForOrAssert(() => !File.Exists(temp), "Temporary file still exists after standard import", 5000);
|
||||||
|
|
||||||
return manager.GetAllUsableBeatmapSets().Find(beatmapSet => beatmapSet.ID == importedSet.Value.ID);
|
return manager.GetAllUsableBeatmapSets().Find(beatmapSet => beatmapSet.ID == importedSet.Value.ID);
|
||||||
}
|
}, TaskCreationOptions.LongRunning);
|
||||||
|
|
||||||
private void deleteBeatmapSet(BeatmapSetInfo imported, OsuGameBase osu)
|
private void deleteBeatmapSet(BeatmapSetInfo imported, OsuGameBase osu)
|
||||||
{
|
{
|
||||||
@ -1053,7 +1055,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
Assert.AreEqual(expected, osu.Dependencies.Get<DatabaseContextFactory>().Get().FileInfo.Count(f => f.ReferenceCount == 1));
|
Assert.AreEqual(expected, osu.Dependencies.Get<DatabaseContextFactory>().Get().FileInfo.Count(f => f.ReferenceCount == 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ensureLoaded(OsuGameBase osu, int timeout = 60000)
|
private static Task ensureLoaded(OsuGameBase osu, int timeout = 60000) => Task.Factory.StartNew(() =>
|
||||||
{
|
{
|
||||||
IEnumerable<BeatmapSetInfo> resultSets = null;
|
IEnumerable<BeatmapSetInfo> resultSets = null;
|
||||||
var store = osu.Dependencies.Get<BeatmapManager>();
|
var store = osu.Dependencies.Get<BeatmapManager>();
|
||||||
@ -1089,14 +1091,14 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
Assert.IsTrue(beatmap?.HitObjects.Any() == true);
|
Assert.IsTrue(beatmap?.HitObjects.Any() == true);
|
||||||
beatmap = store.GetWorkingBeatmap(set.Beatmaps.First(b => b.RulesetID == 3))?.Beatmap;
|
beatmap = store.GetWorkingBeatmap(set.Beatmaps.First(b => b.RulesetID == 3))?.Beatmap;
|
||||||
Assert.IsTrue(beatmap?.HitObjects.Any() == true);
|
Assert.IsTrue(beatmap?.HitObjects.Any() == true);
|
||||||
}
|
}, TaskCreationOptions.LongRunning);
|
||||||
|
|
||||||
private static void waitForOrAssert(Func<bool> result, string failureMessage, int timeout = 60000)
|
private static void waitForOrAssert(Func<bool> result, string failureMessage, int timeout = 60000)
|
||||||
{
|
{
|
||||||
Task task = Task.Run(() =>
|
Task task = Task.Factory.StartNew(() =>
|
||||||
{
|
{
|
||||||
while (!result()) Thread.Sleep(200);
|
while (!result()) Thread.Sleep(200);
|
||||||
});
|
}, TaskCreationOptions.LongRunning);
|
||||||
|
|
||||||
Assert.IsTrue(task.Wait(timeout), failureMessage);
|
Assert.IsTrue(task.Wait(timeout), failureMessage);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user