mirror of
https://github.com/ppy/osu.git
synced 2024-12-13 05:22:54 +08:00
Fix intermittent failure in tests with restarting player instances
This commit is contained in:
parent
8f70424999
commit
13c1b8f5a4
@ -195,11 +195,17 @@ namespace osu.Game.Tests.Visual.Navigation
|
||||
AddUntilStep("wait for player", () =>
|
||||
{
|
||||
DismissAnyNotifications();
|
||||
return (player = Game.ScreenStack.CurrentScreen as Player) != null;
|
||||
player = Game.ScreenStack.CurrentScreen as Player;
|
||||
return player?.IsLoaded == true;
|
||||
});
|
||||
|
||||
AddAssert("retry count is 0", () => player.RestartCount == 0);
|
||||
|
||||
// todo: see https://github.com/ppy/osu/issues/22220
|
||||
// tests are supposed to be immune to this edge case by the logic in TestPlayer,
|
||||
// but we're running a full game instance here, so we have to work around it manually.
|
||||
AddStep("end spectator before retry", () => Game.SpectatorClient.EndPlaying(player.GameplayState));
|
||||
|
||||
AddStep("attempt to retry", () => player.ChildrenOfType<HotkeyRetryOverlay>().First().Action());
|
||||
AddUntilStep("wait for old player gone", () => Game.ScreenStack.CurrentScreen != player);
|
||||
|
||||
|
@ -47,7 +47,7 @@ namespace osu.Game.Online.Spectator
|
||||
/// <summary>
|
||||
/// Whether the local user is playing.
|
||||
/// </summary>
|
||||
protected bool IsPlaying { get; private set; }
|
||||
protected internal bool IsPlaying { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Called whenever new frames arrive from the server.
|
||||
|
@ -189,7 +189,7 @@ namespace osu.Game
|
||||
|
||||
private RulesetConfigCache rulesetConfigCache;
|
||||
|
||||
private SpectatorClient spectatorClient;
|
||||
protected SpectatorClient SpectatorClient { get; private set; }
|
||||
|
||||
protected MultiplayerClient MultiplayerClient { get; private set; }
|
||||
|
||||
@ -300,7 +300,7 @@ namespace osu.Game
|
||||
|
||||
// TODO: OsuGame or OsuGameBase?
|
||||
dependencies.CacheAs(beatmapUpdater = new BeatmapUpdater(BeatmapManager, difficultyCache, API, Storage));
|
||||
dependencies.CacheAs(spectatorClient = new OnlineSpectatorClient(endpoints));
|
||||
dependencies.CacheAs(SpectatorClient = new OnlineSpectatorClient(endpoints));
|
||||
dependencies.CacheAs(MultiplayerClient = new OnlineMultiplayerClient(endpoints));
|
||||
dependencies.CacheAs(metadataClient = new OnlineMetadataClient(endpoints));
|
||||
dependencies.CacheAs(soloStatisticsWatcher = new SoloStatisticsWatcher());
|
||||
@ -346,7 +346,7 @@ namespace osu.Game
|
||||
if (API is APIAccess apiAccess)
|
||||
base.Content.Add(apiAccess);
|
||||
|
||||
base.Content.Add(spectatorClient);
|
||||
base.Content.Add(SpectatorClient);
|
||||
base.Content.Add(MultiplayerClient);
|
||||
base.Content.Add(metadataClient);
|
||||
base.Content.Add(soloStatisticsWatcher);
|
||||
|
@ -20,6 +20,7 @@ using osu.Game.Database;
|
||||
using osu.Game.Graphics.Cursor;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.Spectator;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
@ -148,6 +149,8 @@ namespace osu.Game.Tests.Visual
|
||||
|
||||
public new Bindable<IReadOnlyList<Mod>> SelectedMods => base.SelectedMods;
|
||||
|
||||
public new SpectatorClient SpectatorClient => base.SpectatorClient;
|
||||
|
||||
// if we don't apply these changes, when running under nUnit the version that gets populated is that of nUnit.
|
||||
public override Version AssemblyVersion => new Version(0, 0);
|
||||
public override string Version => "test game";
|
||||
|
@ -8,6 +8,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Online.Spectator;
|
||||
@ -103,6 +104,19 @@ namespace osu.Game.Tests.Visual
|
||||
ScoreProcessor.NewJudgement += r => Results.Add(r);
|
||||
}
|
||||
|
||||
public override bool OnExiting(ScreenExitEvent e)
|
||||
{
|
||||
bool exiting = base.OnExiting(e);
|
||||
|
||||
// SubmittingPlayer performs EndPlaying on a fire-and-forget async task, which allows for the chance of BeginPlaying to be called before EndPlaying is called here.
|
||||
// Until this is handled properly at game-side, ensure EndPlaying is called before exiting player.
|
||||
// see: https://github.com/ppy/osu/issues/22220
|
||||
if (LoadedBeatmapSuccessfully)
|
||||
spectatorClient?.EndPlaying(GameplayState);
|
||||
|
||||
return exiting;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
|
Loading…
Reference in New Issue
Block a user