mirror of
https://github.com/ppy/osu.git
synced 2024-11-13 16:47:46 +08:00
Add failing test case covering online ID reset on save
This test scene passes ate58e1151f3
and fails at current master, due to an inadvertent regression caused bye72f103c17
. As it turns out, the online lookup flow that was causing UI thread freezes when saving beatmaps in the editor, was also responsible for resetting the online ID of locally-modified beatmaps if online lookup failed.
This commit is contained in:
parent
5c066c40b1
commit
8ab3a87b13
@ -0,0 +1,56 @@
|
|||||||
|
// 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.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Extensions;
|
||||||
|
using osu.Game.Database;
|
||||||
|
using osu.Game.Online.API;
|
||||||
|
using osu.Game.Online.API.Requests;
|
||||||
|
using osu.Game.Tests.Resources;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual.Editing
|
||||||
|
{
|
||||||
|
public partial class TestSceneLocallyModifyingOnlineBeatmaps : EditorSavingTestScene
|
||||||
|
{
|
||||||
|
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
|
||||||
|
|
||||||
|
public override void SetUpSteps()
|
||||||
|
{
|
||||||
|
CreateInitialBeatmap = () =>
|
||||||
|
{
|
||||||
|
var importedSet = Game.BeatmapManager.Import(new ImportTask(TestResources.GetTestBeatmapForImport())).GetResultSafely();
|
||||||
|
return Game.BeatmapManager.GetWorkingBeatmap(importedSet!.Value.Beatmaps.First());
|
||||||
|
};
|
||||||
|
|
||||||
|
base.SetUpSteps();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestLocallyModifyingOnlineBeatmap()
|
||||||
|
{
|
||||||
|
AddAssert("editor beatmap has online ID", () => EditorBeatmap.BeatmapInfo.OnlineID, () => Is.GreaterThan(0));
|
||||||
|
|
||||||
|
AddStep("delete first hitobject", () => EditorBeatmap.RemoveAt(0));
|
||||||
|
|
||||||
|
AddStep("mock online lookup failure", () =>
|
||||||
|
{
|
||||||
|
dummyAPI.HandleRequest = req =>
|
||||||
|
{
|
||||||
|
if (req is GetBeatmapRequest)
|
||||||
|
{
|
||||||
|
req.TriggerFailure(new APIException("Beatmap not found", new WebException("NotFound")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
SaveEditor();
|
||||||
|
|
||||||
|
ReloadEditorToSameBeatmap();
|
||||||
|
AddAssert("editor beatmap online ID reset", () => EditorBeatmap.BeatmapInfo.OnlineID, () => Is.EqualTo(-1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -3,9 +3,12 @@
|
|||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using JetBrains.Annotations;
|
||||||
using osu.Framework.Input;
|
using osu.Framework.Input;
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Rulesets.Edit;
|
using osu.Game.Rulesets.Edit;
|
||||||
using osu.Game.Screens.Edit;
|
using osu.Game.Screens.Edit;
|
||||||
using osu.Game.Screens.Edit.Setup;
|
using osu.Game.Screens.Edit.Setup;
|
||||||
@ -24,18 +27,27 @@ namespace osu.Game.Tests.Visual
|
|||||||
|
|
||||||
protected EditorBeatmap EditorBeatmap => (EditorBeatmap)Editor.Dependencies.Get(typeof(EditorBeatmap));
|
protected EditorBeatmap EditorBeatmap => (EditorBeatmap)Editor.Dependencies.Get(typeof(EditorBeatmap));
|
||||||
|
|
||||||
|
[CanBeNull]
|
||||||
|
protected Func<WorkingBeatmap> CreateInitialBeatmap { get; set; }
|
||||||
|
|
||||||
[SetUpSteps]
|
[SetUpSteps]
|
||||||
public override void SetUpSteps()
|
public override void SetUpSteps()
|
||||||
{
|
{
|
||||||
base.SetUpSteps();
|
base.SetUpSteps();
|
||||||
|
|
||||||
AddStep("set default beatmap", () => Game.Beatmap.SetDefault());
|
if (CreateInitialBeatmap == null)
|
||||||
|
AddStep("set default beatmap", () => Game.Beatmap.SetDefault());
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AddStep("set test beatmap", () => Game.Beatmap.Value = CreateInitialBeatmap?.Invoke());
|
||||||
|
}
|
||||||
|
|
||||||
PushAndConfirm(() => new EditorLoader());
|
PushAndConfirm(() => new EditorLoader());
|
||||||
|
|
||||||
AddUntilStep("wait for editor load", () => Editor?.IsLoaded == true);
|
AddUntilStep("wait for editor load", () => Editor?.IsLoaded == true);
|
||||||
|
|
||||||
AddUntilStep("wait for metadata screen load", () => Editor.ChildrenOfType<MetadataSection>().FirstOrDefault()?.IsLoaded == true);
|
if (CreateInitialBeatmap == null)
|
||||||
|
AddUntilStep("wait for metadata screen load", () => Editor.ChildrenOfType<MetadataSection>().FirstOrDefault()?.IsLoaded == true);
|
||||||
|
|
||||||
// We intentionally switch away from the metadata screen, else there is a feedback loop with the textbox handling which causes metadata changes below to get overwritten.
|
// We intentionally switch away from the metadata screen, else there is a feedback loop with the textbox handling which causes metadata changes below to get overwritten.
|
||||||
|
|
||||||
@ -50,6 +62,14 @@ namespace osu.Game.Tests.Visual
|
|||||||
|
|
||||||
protected void ReloadEditorToSameBeatmap()
|
protected void ReloadEditorToSameBeatmap()
|
||||||
{
|
{
|
||||||
|
Guid beatmapSetGuid = Guid.Empty;
|
||||||
|
Guid beatmapGuid = Guid.Empty;
|
||||||
|
|
||||||
|
AddStep("Store beatmap GUIDs", () =>
|
||||||
|
{
|
||||||
|
beatmapSetGuid = EditorBeatmap.BeatmapInfo.BeatmapSet!.ID;
|
||||||
|
beatmapGuid = EditorBeatmap.BeatmapInfo.ID;
|
||||||
|
});
|
||||||
AddStep("Exit", () => InputManager.Key(Key.Escape));
|
AddStep("Exit", () => InputManager.Key(Key.Escape));
|
||||||
|
|
||||||
AddUntilStep("Wait for main menu", () => Game.ScreenStack.CurrentScreen is MainMenu);
|
AddUntilStep("Wait for main menu", () => Game.ScreenStack.CurrentScreen is MainMenu);
|
||||||
@ -59,7 +79,8 @@ namespace osu.Game.Tests.Visual
|
|||||||
PushAndConfirm(() => songSelect = new PlaySongSelect());
|
PushAndConfirm(() => songSelect = new PlaySongSelect());
|
||||||
AddUntilStep("wait for carousel load", () => songSelect.BeatmapSetsLoaded);
|
AddUntilStep("wait for carousel load", () => songSelect.BeatmapSetsLoaded);
|
||||||
|
|
||||||
AddUntilStep("Wait for beatmap selected", () => !Game.Beatmap.IsDefault);
|
AddStep("Present same beatmap", () => Game.PresentBeatmap(Game.BeatmapManager.QueryBeatmapSet(set => set.ID == beatmapSetGuid)!.Value, beatmap => beatmap.ID == beatmapGuid));
|
||||||
|
AddUntilStep("Wait for beatmap selected", () => Game.Beatmap.Value.BeatmapInfo.ID == beatmapGuid);
|
||||||
AddStep("Open options", () => InputManager.Key(Key.F3));
|
AddStep("Open options", () => InputManager.Key(Key.F3));
|
||||||
AddStep("Enter editor", () => InputManager.Key(Key.Number5));
|
AddStep("Enter editor", () => InputManager.Key(Key.Number5));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user