mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 01:22:59 +08:00
Add failing test
This commit is contained in:
parent
e213b338ce
commit
de23364608
@ -5,6 +5,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
@ -19,6 +20,7 @@ using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.Notifications;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Osu;
|
||||
using osu.Game.Rulesets.Osu.Mods;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using osu.Game.Scoring;
|
||||
using osu.Game.Screens;
|
||||
@ -55,6 +57,9 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
beforeLoadAction?.Invoke();
|
||||
Beatmap.Value = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
|
||||
|
||||
foreach (var mod in Mods.Value.OfType<IApplicableToClock>())
|
||||
mod.ApplyToClock(Beatmap.Value.Track);
|
||||
|
||||
InputManager.Child = container = new TestPlayerLoaderContainer(
|
||||
loader = new TestPlayerLoader(() =>
|
||||
{
|
||||
@ -63,6 +68,25 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
}));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When <see cref="PlayerLoader"/> exits early, it has to wait for the player load task
|
||||
/// to complete before running disposal on player. This previously caused an issue where mod
|
||||
/// speed adjustments were undone too late, causing cross-screen pollution.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestEarlyExit()
|
||||
{
|
||||
AddStep("apply mods", () => Mods.Value = new[] { new OsuModNightcore() });
|
||||
AddStep("load dummy beatmap", () => ResetPlayer(false));
|
||||
AddUntilStep("wait for current", () => loader.IsCurrentScreen());
|
||||
AddAssert("mod rate applied", () => Beatmap.Value.Track.Rate != 1);
|
||||
AddStep("exit loader", () => loader.Exit());
|
||||
AddUntilStep("wait for not current", () => !loader.IsCurrentScreen());
|
||||
AddAssert("player did not load", () => !player.IsLoaded);
|
||||
AddUntilStep("player disposed", () => loader.DisposalTask?.IsCompleted == true);
|
||||
AddAssert("mod rate still applied", () => Beatmap.Value.Track.Rate != 1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestBlockLoadViaMouseMovement()
|
||||
{
|
||||
@ -196,6 +220,8 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
{
|
||||
public new VisualSettings VisualSettings => base.VisualSettings;
|
||||
|
||||
public new Task DisposalTask => base.DisposalTask;
|
||||
|
||||
public TestPlayerLoader(Func<Player> createPlayer)
|
||||
: base(createPlayer)
|
||||
{
|
||||
|
@ -55,7 +55,9 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
protected override bool PlayResumeSound => false;
|
||||
|
||||
private Task loadTask;
|
||||
protected Task LoadTask;
|
||||
|
||||
protected Task DisposalTask;
|
||||
|
||||
private InputManager inputManager;
|
||||
private IdleTracker idleTracker;
|
||||
@ -159,7 +161,7 @@ namespace osu.Game.Screens.Play
|
||||
player.RestartCount = restartCount;
|
||||
player.RestartRequested = restartRequested;
|
||||
|
||||
loadTask = LoadComponentAsync(player, _ => info.Loading = false);
|
||||
LoadTask = LoadComponentAsync(player, _ => info.Loading = false);
|
||||
}
|
||||
|
||||
private void contentIn()
|
||||
@ -250,7 +252,7 @@ namespace osu.Game.Screens.Play
|
||||
{
|
||||
if (!this.IsCurrentScreen()) return;
|
||||
|
||||
loadTask = null;
|
||||
LoadTask = null;
|
||||
|
||||
//By default, we want to load the player and never be returned to.
|
||||
//Note that this may change if the player we load requested a re-run.
|
||||
@ -301,7 +303,7 @@ namespace osu.Game.Screens.Play
|
||||
if (isDisposing)
|
||||
{
|
||||
// if the player never got pushed, we should explicitly dispose it.
|
||||
loadTask?.ContinueWith(_ => player.Dispose());
|
||||
DisposalTask = LoadTask?.ContinueWith(_ => player.Dispose());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user