Move UserLookupCache inside dependencies

This commit is contained in:
smoogipoo 2021-06-25 17:37:02 +09:00
parent d6ab08c958
commit 7aefbe3da1
11 changed files with 46 additions and 69 deletions

View File

@ -2,8 +2,6 @@
// See the LICENCE file in the repository root for full licence text.
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
@ -232,14 +230,5 @@ private void loadSpectatingScreen()
AddStep("load screen", () => LoadScreen(spectatorScreen = new SoloSpectator(streamingUser)));
AddUntilStep("wait for screen load", () => spectatorScreen.LoadState == LoadState.Loaded);
}
internal class TestUserLookupCache : UserLookupCache
{
protected override Task<User> ComputeValueAsync(int lookup, CancellationToken token = default) => Task.FromResult(new User
{
Id = lookup,
Username = $"User {lookup}"
});
}
}
}

View File

@ -3,19 +3,15 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;
using osu.Framework.Testing;
using osu.Framework.Timing;
using osu.Game.Database;
using osu.Game.Online.Spectator;
using osu.Game.Rulesets.Osu.Scoring;
using osu.Game.Screens.OnlinePlay.Multiplayer.Spectate;
using osu.Game.Screens.Play.HUD;
using osu.Game.Tests.Visual.OnlinePlay;
using osu.Game.Tests.Visual.Spectator;
using osu.Game.Users;
namespace osu.Game.Tests.Visual.Multiplayer
{
@ -128,24 +124,10 @@ private void assertCombo(int userId, int expectedCombo)
protected class TestDependencies : MultiplayerRoomTestDependencies
{
public readonly TestSpectatorClient SpectatorClient = new TestSpectatorClient();
public readonly UserLookupCache LookupCache = new TestUserLookupCache();
public TestDependencies()
{
CacheAs<SpectatorClient>(SpectatorClient);
CacheAs(LookupCache);
}
}
private class TestUserLookupCache : UserLookupCache
{
protected override Task<User> ComputeValueAsync(int lookup, CancellationToken token = default)
{
return Task.FromResult(new User
{
Id = lookup,
Username = $"User {lookup}"
});
}
}
}

View File

@ -3,21 +3,17 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Online.Spectator;
using osu.Game.Screens.OnlinePlay.Multiplayer.Spectate;
using osu.Game.Screens.Play;
using osu.Game.Tests.Beatmaps.IO;
using osu.Game.Tests.Visual.OnlinePlay;
using osu.Game.Tests.Visual.Spectator;
using osu.Game.Users;
namespace osu.Game.Tests.Visual.Multiplayer
{
@ -289,24 +285,10 @@ private void waitForCatchup(int userId)
protected class TestDependencies : MultiplayerRoomTestDependencies
{
public readonly TestSpectatorClient SpectatorClient = new TestSpectatorClient();
public readonly UserLookupCache LookupCache = new TestUserLookupCache();
public TestDependencies()
{
CacheAs<SpectatorClient>(SpectatorClient);
CacheAs(LookupCache);
}
}
internal class TestUserLookupCache : UserLookupCache
{
protected override Task<User> ComputeValueAsync(int lookup, CancellationToken token = default)
{
return Task.FromResult(new User
{
Id = lookup,
Username = $"User {lookup}"
});
}
}
}

View File

@ -6,11 +6,11 @@
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Configuration;
using osu.Game.Database;
using osu.Game.Online.API;
using osu.Game.Online.Spectator;
using osu.Game.Replays.Legacy;
@ -18,7 +18,6 @@
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
using osu.Game.Screens.Play.HUD;
using osu.Game.Tests.Visual.Online;
using osu.Game.Tests.Visual.OnlinePlay;
using osu.Game.Tests.Visual.Spectator;
@ -26,12 +25,10 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
public class TestSceneMultiplayerGameplayLeaderboard : MultiplayerTestScene
{
private const int users = 16;
private static IEnumerable<int> users => Enumerable.Range(0, 16);
public TestMultiplayerSpectatorClient SpectatorClient => RoomDependencies?.SpectatorClient;
public UserLookupCache LookupCache => RoomDependencies?.LookupCache;
protected new TestDependencies RoomDependencies => (TestDependencies)base.RoomDependencies;
private MultiplayerGameplayLeaderboard leaderboard;
@ -57,14 +54,11 @@ public override void SetUpSteps()
var playable = Beatmap.Value.GetPlayableBeatmap(Ruleset.Value);
for (int i = 0; i < users; i++)
SpectatorClient.StartPlay(i, Beatmap.Value.BeatmapInfo.OnlineBeatmapID ?? 0);
foreach (var user in users)
SpectatorClient.StartPlay(user, Beatmap.Value.BeatmapInfo.OnlineBeatmapID ?? 0);
SpectatorClient.Schedule(() =>
{
Client.CurrentMatchPlayingUserIds.Clear();
Client.CurrentMatchPlayingUserIds.AddRange(SpectatorClient.PlayingUsers);
});
// Todo: This is REALLY bad.
Client.CurrentMatchPlayingUserIds.AddRange(users);
Children = new Drawable[]
{
@ -73,7 +67,7 @@ public override void SetUpSteps()
scoreProcessor.ApplyBeatmap(playable);
LoadComponentAsync(leaderboard = new MultiplayerGameplayLeaderboard(scoreProcessor, SpectatorClient.PlayingUsers.ToArray())
LoadComponentAsync(leaderboard = new MultiplayerGameplayLeaderboard(scoreProcessor, users.ToArray())
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
@ -94,7 +88,8 @@ public void TestScoreUpdates()
[Test]
public void TestUserQuit()
{
AddRepeatStep("mark user quit", () => Client.CurrentMatchPlayingUserIds.RemoveAt(0), users);
foreach (var user in users)
AddStep($"mark user {user} quit", () => Client.RemoveUser(LookupCache.GetUserAsync(user).Result.AsNonNull()));
}
[Test]
@ -110,12 +105,10 @@ public void TestChangeScoringMode()
protected class TestDependencies : MultiplayerRoomTestDependencies
{
public readonly TestMultiplayerSpectatorClient SpectatorClient = new TestMultiplayerSpectatorClient();
public readonly UserLookupCache LookupCache = new TestSceneCurrentlyPlayingDisplay.TestUserLookupCache();
public TestDependencies()
{
CacheAs<SpectatorClient>(SpectatorClient);
CacheAs(LookupCache);
}
}

View File

@ -1,13 +1,14 @@
// 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 osu.Game.Database;
using osu.Game.Online.Multiplayer;
using osu.Game.Screens.OnlinePlay;
using osu.Game.Tests.Visual.OnlinePlay;
namespace osu.Game.Tests.Visual.Multiplayer
{
public interface IMultiplayerRoomTestDependencies : IRoomTestDependencies
public interface IMultiplayerTestDependencies : IOnlinePlayTestDependencies
{
/// <summary>
/// The cached <see cref="MultiplayerClient"/>.
@ -18,5 +19,10 @@ public interface IMultiplayerRoomTestDependencies : IRoomTestDependencies
/// The cached <see cref="IRoomManager"/>.
/// </summary>
new TestMultiplayerRoomManager RoomManager { get; }
/// <summary>
/// The cached <see cref="UserLookupCache"/>.
/// </summary>
TestUserLookupCache LookupCache { get; }
}
}

View File

@ -1,21 +1,26 @@
// 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 osu.Game.Database;
using osu.Game.Online.Multiplayer;
using osu.Game.Screens.OnlinePlay;
using osu.Game.Tests.Visual.OnlinePlay;
namespace osu.Game.Tests.Visual.Multiplayer
{
public class MultiplayerRoomTestDependencies : RoomTestDependencies, IMultiplayerRoomTestDependencies
public class MultiplayerRoomTestDependencies : RoomTestDependencies, IMultiplayerTestDependencies
{
public TestMultiplayerClient Client { get; }
public TestUserLookupCache LookupCache { get; }
public new TestMultiplayerRoomManager RoomManager => (TestMultiplayerRoomManager)base.RoomManager;
public MultiplayerRoomTestDependencies()
{
Client = new TestMultiplayerClient(RoomManager);
LookupCache = new TestUserLookupCache();
CacheAs<MultiplayerClient>(Client);
CacheAs<UserLookupCache>(LookupCache);
}
protected override IRoomManager CreateRoomManager() => new TestMultiplayerRoomManager();

View File

@ -8,13 +8,14 @@
namespace osu.Game.Tests.Visual.Multiplayer
{
public abstract class MultiplayerTestScene : OnlinePlayTestScene
public abstract class MultiplayerTestScene : OnlinePlayTestScene, IMultiplayerTestDependencies
{
public const int PLAYER_1_ID = 55;
public const int PLAYER_2_ID = 56;
public TestMultiplayerClient Client => RoomDependencies.Client;
public new TestMultiplayerRoomManager RoomManager => RoomDependencies.RoomManager;
public TestUserLookupCache LookupCache => RoomDependencies?.LookupCache;
protected new MultiplayerRoomTestDependencies RoomDependencies => (MultiplayerRoomTestDependencies)base.RoomDependencies;

View File

@ -8,7 +8,7 @@
namespace osu.Game.Tests.Visual.OnlinePlay
{
public interface IRoomTestDependencies
public interface IOnlinePlayTestDependencies
{
/// <summary>
/// The cached <see cref="Room"/>.

View File

@ -16,7 +16,7 @@ namespace osu.Game.Tests.Visual.OnlinePlay
/// <summary>
/// A <see cref="ScreenTestScene"/> providing all the dependencies cached by <see cref="OnlinePlayScreen"/> for testing <see cref="OnlinePlaySubScreen"/>s.
/// </summary>
public abstract class OnlinePlayTestScene : ScreenTestScene, IRoomTestDependencies
public abstract class OnlinePlayTestScene : ScreenTestScene, IOnlinePlayTestDependencies
{
public Bindable<Room> SelectedRoom => RoomDependencies?.SelectedRoom;
public IRoomManager RoomManager => RoomDependencies?.RoomManager;

View File

@ -15,7 +15,7 @@ namespace osu.Game.Tests.Visual.OnlinePlay
/// <summary>
/// Contains dependencies for testing online-play rooms.
/// </summary>
public class RoomTestDependencies : IReadOnlyDependencyContainer, IRoomTestDependencies
public class RoomTestDependencies : IReadOnlyDependencyContainer, IOnlinePlayTestDependencies
{
public Bindable<Room> SelectedRoom { get; }
public IRoomManager RoomManager { get; }

View File

@ -0,0 +1,19 @@
// 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.Threading;
using System.Threading.Tasks;
using osu.Game.Database;
using osu.Game.Users;
namespace osu.Game.Tests.Visual
{
public class TestUserLookupCache : UserLookupCache
{
protected override Task<User> ComputeValueAsync(int lookup, CancellationToken token = default) => Task.FromResult(new User
{
Id = lookup,
Username = $"User {lookup}"
});
}
}