1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 11:42:56 +08:00

Merge pull request #19656 from smoogipoo/fix-gameplay-test-rerun

Fix gameplay tests crashing when run multiple times
This commit is contained in:
Dean Herbert 2022-08-09 16:01:39 +09:00 committed by GitHub
commit 47ca812faf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,6 +10,7 @@ using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
using osu.Game.Online.Spectator;
using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
@ -46,6 +47,9 @@ namespace osu.Game.Tests.Visual
public readonly List<JudgementResult> Results = new List<JudgementResult>(); public readonly List<JudgementResult> Results = new List<JudgementResult>();
[Resolved]
private SpectatorClient spectatorClient { get; set; }
public TestPlayer(bool allowPause = true, bool showResults = true, bool pauseOnFocusLost = false) public TestPlayer(bool allowPause = true, bool showResults = true, bool pauseOnFocusLost = false)
: base(new PlayerConfiguration : base(new PlayerConfiguration
{ {
@ -98,5 +102,15 @@ namespace osu.Game.Tests.Visual
ScoreProcessor.NewJudgement += r => Results.Add(r); ScoreProcessor.NewJudgement += r => Results.Add(r);
} }
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
// Specific to tests, the player can be disposed without OnExiting() ever being called.
// We should make sure that the gameplay session has finished even in this case.
if (LoadedBeatmapSuccessfully)
spectatorClient.EndPlaying(GameplayState);
}
} }
} }