mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 17:23:22 +08:00
Merge pull request #14115 from smoogipoo/fix-spectator-test-failures
Fix spectator test failures
This commit is contained in:
commit
b43f5f755d
@ -13,6 +13,7 @@ using osu.Game.Online.Spectator;
|
||||
using osu.Game.Rulesets.Osu;
|
||||
using osu.Game.Rulesets.Osu.Replays;
|
||||
using osu.Game.Rulesets.UI;
|
||||
using osu.Game.Screens;
|
||||
using osu.Game.Screens.Play;
|
||||
using osu.Game.Tests.Beatmaps.IO;
|
||||
using osu.Game.Tests.Visual.Multiplayer;
|
||||
@ -25,41 +26,43 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
{
|
||||
private readonly User streamingUser = new User { Id = MultiplayerTestScene.PLAYER_1_ID, Username = "Test user" };
|
||||
|
||||
[Cached(typeof(SpectatorClient))]
|
||||
private TestSpectatorClient testSpectatorClient = new TestSpectatorClient();
|
||||
|
||||
[Cached(typeof(UserLookupCache))]
|
||||
private UserLookupCache lookupCache = new TestUserLookupCache();
|
||||
|
||||
// used just to show beatmap card for the time being.
|
||||
protected override bool UseOnlineAPI => true;
|
||||
|
||||
private SoloSpectator spectatorScreen;
|
||||
|
||||
[Resolved]
|
||||
private OsuGameBase game { get; set; }
|
||||
|
||||
private BeatmapSetInfo importedBeatmap;
|
||||
private TestSpectatorClient spectatorClient;
|
||||
private SoloSpectator spectatorScreen;
|
||||
|
||||
private BeatmapSetInfo importedBeatmap;
|
||||
private int importedBeatmapId;
|
||||
|
||||
public override void SetUpSteps()
|
||||
[SetUpSteps]
|
||||
public void SetupSteps()
|
||||
{
|
||||
base.SetUpSteps();
|
||||
DependenciesScreen dependenciesScreen = null;
|
||||
|
||||
AddStep("load dependencies", () =>
|
||||
{
|
||||
spectatorClient = new TestSpectatorClient();
|
||||
|
||||
// The screen gets suspended so it stops receiving updates.
|
||||
Child = spectatorClient;
|
||||
|
||||
LoadScreen(dependenciesScreen = new DependenciesScreen(spectatorClient));
|
||||
});
|
||||
|
||||
AddUntilStep("wait for dependencies to load", () => dependenciesScreen.IsLoaded);
|
||||
|
||||
AddStep("import beatmap", () =>
|
||||
{
|
||||
importedBeatmap = ImportBeatmapTest.LoadOszIntoOsu(game, virtualTrack: true).Result;
|
||||
importedBeatmapId = importedBeatmap.Beatmaps.First(b => b.RulesetID == 0).OnlineBeatmapID ?? -1;
|
||||
});
|
||||
|
||||
AddStep("add streaming client", () =>
|
||||
{
|
||||
Remove(testSpectatorClient);
|
||||
Add(testSpectatorClient);
|
||||
});
|
||||
|
||||
finish();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -206,22 +209,36 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
|
||||
private void waitForPlayer() => AddUntilStep("wait for player", () => (Stack.CurrentScreen as Player)?.IsLoaded == true);
|
||||
|
||||
private void start(int? beatmapId = null) => AddStep("start play", () => testSpectatorClient.StartPlay(streamingUser.Id, beatmapId ?? importedBeatmapId));
|
||||
private void start(int? beatmapId = null) => AddStep("start play", () => spectatorClient.StartPlay(streamingUser.Id, beatmapId ?? importedBeatmapId));
|
||||
|
||||
private void finish() => AddStep("end play", () => testSpectatorClient.EndPlay(streamingUser.Id));
|
||||
private void finish() => AddStep("end play", () => spectatorClient.EndPlay(streamingUser.Id));
|
||||
|
||||
private void checkPaused(bool state) =>
|
||||
AddUntilStep($"game is {(state ? "paused" : "playing")}", () => player.ChildrenOfType<DrawableRuleset>().First().IsPaused.Value == state);
|
||||
|
||||
private void sendFrames(int count = 10)
|
||||
{
|
||||
AddStep("send frames", () => testSpectatorClient.SendFrames(streamingUser.Id, count));
|
||||
AddStep("send frames", () => spectatorClient.SendFrames(streamingUser.Id, count));
|
||||
}
|
||||
|
||||
private void loadSpectatingScreen()
|
||||
{
|
||||
AddStep("load screen", () => LoadScreen(spectatorScreen = new SoloSpectator(streamingUser)));
|
||||
AddStep("load spectator", () => LoadScreen(spectatorScreen = new SoloSpectator(streamingUser)));
|
||||
AddUntilStep("wait for screen load", () => spectatorScreen.LoadState == LoadState.Loaded);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used for the sole purpose of adding <see cref="TestSpectatorClient"/> as a resolvable dependency.
|
||||
/// </summary>
|
||||
private class DependenciesScreen : OsuScreen
|
||||
{
|
||||
[Cached(typeof(SpectatorClient))]
|
||||
public readonly TestSpectatorClient Client;
|
||||
|
||||
public DependenciesScreen(TestSpectatorClient client)
|
||||
{
|
||||
Client = client;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,12 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Online.Spectator;
|
||||
@ -21,51 +20,44 @@ namespace osu.Game.Tests.Visual.Online
|
||||
{
|
||||
private readonly User streamingUser = new User { Id = 2, Username = "Test user" };
|
||||
|
||||
[Cached(typeof(SpectatorClient))]
|
||||
private TestSpectatorClient testSpectatorClient = new TestSpectatorClient();
|
||||
|
||||
private TestSpectatorClient spectatorClient;
|
||||
private CurrentlyPlayingDisplay currentlyPlaying;
|
||||
|
||||
[Cached(typeof(UserLookupCache))]
|
||||
private UserLookupCache lookupCache = new TestUserLookupCache();
|
||||
|
||||
private Container nestedContainer;
|
||||
|
||||
[SetUpSteps]
|
||||
public void SetUpSteps()
|
||||
{
|
||||
AddStep("add streaming client", () =>
|
||||
{
|
||||
nestedContainer?.Remove(testSpectatorClient);
|
||||
Remove(lookupCache);
|
||||
spectatorClient = new TestSpectatorClient();
|
||||
var lookupCache = new TestUserLookupCache();
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
lookupCache,
|
||||
nestedContainer = new Container
|
||||
spectatorClient,
|
||||
new DependencyProvidingContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
CachedDependencies = new (Type, object)[]
|
||||
{
|
||||
testSpectatorClient,
|
||||
currentlyPlaying = new CurrentlyPlayingDisplay
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
}
|
||||
(typeof(SpectatorClient), spectatorClient),
|
||||
(typeof(UserLookupCache), lookupCache)
|
||||
},
|
||||
Child = currentlyPlaying = new CurrentlyPlayingDisplay
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
}
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
AddStep("Reset players", () => testSpectatorClient.EndPlay(streamingUser.Id));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestBasicDisplay()
|
||||
{
|
||||
AddStep("Add playing user", () => testSpectatorClient.StartPlay(streamingUser.Id, 0));
|
||||
AddStep("Add playing user", () => spectatorClient.StartPlay(streamingUser.Id, 0));
|
||||
AddUntilStep("Panel loaded", () => currentlyPlaying.ChildrenOfType<UserGridPanel>()?.FirstOrDefault()?.User.Id == 2);
|
||||
AddStep("Remove playing user", () => testSpectatorClient.EndPlay(streamingUser.Id));
|
||||
AddStep("Remove playing user", () => spectatorClient.EndPlay(streamingUser.Id));
|
||||
AddUntilStep("Panel no longer present", () => !currentlyPlaying.ChildrenOfType<UserGridPanel>().Any());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user