1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 09:22:58 +08:00

Merge pull request #29715 from bdach/fix-stall-on-empty-replay-import-attempt

Fix stall when attempting to import replay after hitting nothing
This commit is contained in:
Dean Herbert 2024-09-07 22:01:31 +09:00 committed by GitHub
commit 7f687d545d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 39 additions and 4 deletions

View File

@ -8,7 +8,9 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;
using osu.Framework.Graphics.Containers;
using osu.Framework.Screens;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Online.API;
using osu.Game.Online.Rooms;
@ -26,6 +28,7 @@ using osu.Game.Scoring;
using osu.Game.Screens.Play;
using osu.Game.Screens.Ranking;
using osu.Game.Tests.Beatmaps;
using osuTK.Input;
namespace osu.Game.Tests.Visual.Gameplay
{
@ -177,6 +180,30 @@ namespace osu.Game.Tests.Visual.Gameplay
AddAssert("ensure no submission", () => Player.SubmittedScore == null);
}
[Test]
public void TestEmptyFailStillImports()
{
prepareTestAPI(true);
createPlayerTest(true);
AddUntilStep("wait for token request", () => Player.TokenCreationRequested);
AddUntilStep("wait for fail", () => Player.GameplayState.HasFailed);
AddUntilStep("wait for fail overlay", () => Player.FailOverlay.State.Value, () => Is.EqualTo(Visibility.Visible));
AddStep("attempt import", () =>
{
InputManager.MoveMouseTo(Player.ChildrenOfType<SaveFailedScoreButton>().Single());
InputManager.Click(MouseButton.Left);
});
AddUntilStep("wait for import to start", () => Player.ScoreImportStarted);
AddStep("allow import", () => Player.AllowImportCompletion.Release());
AddUntilStep("import completed", () => Player.ImportedScore, () => Is.Not.Null);
AddAssert("ensure no submission", () => Player.SubmittedScore, () => Is.Null);
}
[Test]
public void TestSubmissionOnFail()
{
@ -378,6 +405,8 @@ namespace osu.Game.Tests.Visual.Gameplay
public SemaphoreSlim AllowImportCompletion { get; }
public Score ImportedScore { get; private set; }
public new FailOverlay FailOverlay => base.FailOverlay;
public FakeImportingPlayer(bool allowPause = true, bool showResults = true, bool pauseOnFocusLost = false)
: base(allowPause, showResults, pauseOnFocusLost)
{

View File

@ -274,6 +274,16 @@ namespace osu.Game.Screens.Play
return Task.CompletedTask;
}
// if the user never hit anything, this score should not be counted in any way.
if (!score.ScoreInfo.Statistics.Any(s => s.Key.IsHit() && s.Value > 0))
{
Logger.Log("No hits registered, skipping score submission");
return Task.CompletedTask;
}
// mind the timing of this.
// once `scoreSubmissionSource` is created, it is presumed that submission is taking place in the background,
// so all exceptional circumstances that would disallow submission must be handled above.
lock (scoreSubmissionLock)
{
if (scoreSubmissionSource != null)
@ -282,10 +292,6 @@ namespace osu.Game.Screens.Play
scoreSubmissionSource = new TaskCompletionSource<bool>();
}
// if the user never hit anything, this score should not be counted in any way.
if (!score.ScoreInfo.Statistics.Any(s => s.Key.IsHit() && s.Value > 0))
return Task.CompletedTask;
Logger.Log($"Beginning score submission (token:{token.Value})...");
var request = CreateSubmissionRequest(score, token.Value);