Skip to content

Commit

Permalink
Merge pull request #29715 from bdach/fix-stall-on-empty-replay-import…
Browse files Browse the repository at this point in the history
…-attempt

Fix stall when attempting to import replay after hitting nothing
  • Loading branch information
peppy authored Sep 7, 2024
2 parents 10ef5a6 + 4e9ad13 commit 7f687d5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
29 changes: 29 additions & 0 deletions osu.Game.Tests/Visual/Gameplay/TestScenePlayerScoreSubmission.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
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;
Expand All @@ -26,6 +28,7 @@
using osu.Game.Screens.Play;
using osu.Game.Screens.Ranking;
using osu.Game.Tests.Beatmaps;
using osuTK.Input;

namespace osu.Game.Tests.Visual.Gameplay
{
Expand Down Expand Up @@ -177,6 +180,30 @@ public void TestNoSubmissionOnEmptyFail()
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()
{
Expand Down Expand Up @@ -378,6 +405,8 @@ protected partial class FakeImportingPlayer : TestPlayer
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)
{
Expand Down
14 changes: 10 additions & 4 deletions osu.Game/Screens/Play/SubmittingPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,16 @@ private Task submitScore(Score score)
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)
Expand All @@ -282,10 +292,6 @@ private Task submitScore(Score score)
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);

Expand Down

0 comments on commit 7f687d5

Please sign in to comment.