1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 17:32:54 +08:00

Merge pull request #19453 from smoogipoo/multiplayer-test-misordering

Fix potential test failures due to Setup/SetUpSteps ordering
This commit is contained in:
Dean Herbert 2022-07-29 15:59:51 +09:00 committed by GitHub
commit be7a9e1487
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 258 additions and 221 deletions

View File

@ -19,29 +19,33 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
private DrawableRoomParticipantsList list; private DrawableRoomParticipantsList list;
[SetUp] public override void SetUpSteps()
public new void Setup() => Schedule(() =>
{ {
SelectedRoom.Value = new Room base.SetUpSteps();
{
Name = { Value = "test room" },
Host =
{
Value = new APIUser
{
Id = 2,
Username = "peppy",
}
}
};
Child = list = new DrawableRoomParticipantsList AddStep("create list", () =>
{ {
Anchor = Anchor.Centre, SelectedRoom.Value = new Room
Origin = Anchor.Centre, {
NumberOfCircles = 4 Name = { Value = "test room" },
}; Host =
}); {
Value = new APIUser
{
Id = 2,
Username = "peppy",
}
}
};
Child = list = new DrawableRoomParticipantsList
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
NumberOfCircles = 4
};
});
}
[Test] [Test]
public void TestCircleCountNearLimit() public void TestCircleCountNearLimit()

View File

@ -25,23 +25,27 @@ namespace osu.Game.Tests.Visual.Multiplayer
private RoomsContainer container; private RoomsContainer container;
[SetUp] public override void SetUpSteps()
public new void Setup() => Schedule(() =>
{ {
Child = new PopoverContainer base.SetUpSteps();
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Width = 0.5f,
Child = container = new RoomsContainer AddStep("create container", () =>
{
Child = new PopoverContainer
{ {
SelectedRoom = { BindTarget = SelectedRoom } RelativeSizeAxes = Axes.X,
} AutoSizeAxes = Axes.Y,
}; Anchor = Anchor.Centre,
}); Origin = Anchor.Centre,
Width = 0.5f,
Child = container = new RoomsContainer
{
SelectedRoom = { BindTarget = SelectedRoom }
}
};
});
}
[Test] [Test]
public void TestBasicListChanges() public void TestBasicListChanges()

View File

@ -3,7 +3,6 @@
#nullable disable #nullable disable
using NUnit.Framework;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
@ -18,19 +17,23 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
public class TestSceneMatchBeatmapDetailArea : OnlinePlayTestScene public class TestSceneMatchBeatmapDetailArea : OnlinePlayTestScene
{ {
[SetUp] public override void SetUpSteps()
public new void Setup() => Schedule(() =>
{ {
SelectedRoom.Value = new Room(); base.SetUpSteps();
Child = new MatchBeatmapDetailArea AddStep("create area", () =>
{ {
Anchor = Anchor.Centre, SelectedRoom.Value = new Room();
Origin = Anchor.Centre,
Size = new Vector2(500), Child = new MatchBeatmapDetailArea
CreateNewItem = createNewItem {
}; Anchor = Anchor.Centre,
}); Origin = Anchor.Centre,
Size = new Vector2(500),
CreateNewItem = createNewItem
};
});
}
private void createNewItem() private void createNewItem()
{ {

View File

@ -4,8 +4,6 @@
#nullable disable #nullable disable
using System.Collections.Generic; using System.Collections.Generic;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
@ -19,59 +17,62 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
public class TestSceneMatchLeaderboard : OnlinePlayTestScene public class TestSceneMatchLeaderboard : OnlinePlayTestScene
{ {
[BackgroundDependencyLoader] public override void SetUpSteps()
private void load()
{ {
((DummyAPIAccess)API).HandleRequest = r => base.SetUpSteps();
AddStep("setup API", () =>
{ {
switch (r) ((DummyAPIAccess)API).HandleRequest = r =>
{ {
case GetRoomLeaderboardRequest leaderboardRequest: switch (r)
leaderboardRequest.TriggerSuccess(new APILeaderboard {
{ case GetRoomLeaderboardRequest leaderboardRequest:
Leaderboard = new List<APIUserScoreAggregate> leaderboardRequest.TriggerSuccess(new APILeaderboard
{ {
new APIUserScoreAggregate Leaderboard = new List<APIUserScoreAggregate>
{ {
UserID = 2, new APIUserScoreAggregate
User = new APIUser { Id = 2, Username = "peppy" }, {
TotalScore = 995533, UserID = 2,
RoomID = 3, User = new APIUser { Id = 2, Username = "peppy" },
CompletedBeatmaps = 1, TotalScore = 995533,
TotalAttempts = 6, RoomID = 3,
Accuracy = 0.9851 CompletedBeatmaps = 1,
}, TotalAttempts = 6,
new APIUserScoreAggregate Accuracy = 0.9851
{ },
UserID = 1040328, new APIUserScoreAggregate
User = new APIUser { Id = 1040328, Username = "smoogipoo" }, {
TotalScore = 981100, UserID = 1040328,
RoomID = 3, User = new APIUser { Id = 1040328, Username = "smoogipoo" },
CompletedBeatmaps = 1, TotalScore = 981100,
TotalAttempts = 9, RoomID = 3,
Accuracy = 0.937 CompletedBeatmaps = 1,
TotalAttempts = 9,
Accuracy = 0.937
}
} }
} });
}); return true;
return true; }
}
return false; return false;
}; };
} });
[SetUp] AddStep("create leaderboard", () =>
public new void Setup() => Schedule(() =>
{
SelectedRoom.Value = new Room { RoomID = { Value = 3 } };
Child = new MatchLeaderboard
{ {
Origin = Anchor.Centre, SelectedRoom.Value = new Room { RoomID = { Value = 3 } };
Anchor = Anchor.Centre,
Size = new Vector2(550f, 450f), Child = new MatchLeaderboard
Scope = MatchLeaderboardScope.Overall, {
}; Origin = Anchor.Centre,
}); Anchor = Anchor.Centre,
Size = new Vector2(550f, 450f),
Scope = MatchLeaderboardScope.Overall,
};
});
}
} }
} }

View File

@ -22,8 +22,10 @@ namespace osu.Game.Tests.Visual.Multiplayer
private MultiSpectatorLeaderboard leaderboard; private MultiSpectatorLeaderboard leaderboard;
[SetUpSteps] [SetUpSteps]
public new void SetUpSteps() public override void SetUpSteps()
{ {
base.SetUpSteps();
AddStep("reset", () => AddStep("reset", () =>
{ {
leaderboard?.RemoveAndDisposeImmediately(); leaderboard?.RemoveAndDisposeImmediately();

View File

@ -56,8 +56,12 @@ namespace osu.Game.Tests.Visual.Multiplayer
importedBeatmapId = importedBeatmap.OnlineID; importedBeatmapId = importedBeatmap.OnlineID;
} }
[SetUp] public override void SetUpSteps()
public new void Setup() => Schedule(() => playingUsers.Clear()); {
base.SetUpSteps();
AddStep("clear playing users", () => playingUsers.Clear());
}
[Test] [Test]
public void TestDelayedStart() public void TestDelayedStart()

View File

@ -3,7 +3,6 @@
#nullable disable #nullable disable
using NUnit.Framework;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Cursor;
@ -13,23 +12,27 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
public class TestSceneMultiplayerMatchFooter : MultiplayerTestScene public class TestSceneMultiplayerMatchFooter : MultiplayerTestScene
{ {
[SetUp] public override void SetUpSteps()
public new void Setup() => Schedule(() =>
{ {
Child = new PopoverContainer base.SetUpSteps();
AddStep("create footer", () =>
{ {
Anchor = Anchor.Centre, Child = new PopoverContainer
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Child = new Container
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.Both,
Height = 50, Child = new Container
Child = new MultiplayerMatchFooter() {
} Anchor = Anchor.Centre,
}; Origin = Anchor.Centre,
}); RelativeSizeAxes = Axes.X,
Height = 50,
Child = new MultiplayerMatchFooter()
}
};
});
}
} }
} }

View File

@ -59,16 +59,15 @@ namespace osu.Game.Tests.Visual.Multiplayer
importedSet = beatmaps.GetAllUsableBeatmapSets().First(); importedSet = beatmaps.GetAllUsableBeatmapSets().First();
} }
[SetUp]
public new void Setup() => Schedule(() =>
{
SelectedRoom.Value = new Room { Name = { Value = "Test Room" } };
});
[SetUpSteps] [SetUpSteps]
public void SetupSteps() public void SetupSteps()
{ {
AddStep("load match", () => LoadScreen(screen = new MultiplayerMatchSubScreen(SelectedRoom.Value))); AddStep("load match", () =>
{
SelectedRoom.Value = new Room { Name = { Value = "Test Room" } };
LoadScreen(screen = new MultiplayerMatchSubScreen(SelectedRoom.Value));
});
AddUntilStep("wait for load", () => screen.IsCurrentScreen()); AddUntilStep("wait for load", () => screen.IsCurrentScreen());
} }

View File

@ -42,21 +42,22 @@ namespace osu.Game.Tests.Visual.Multiplayer
Dependencies.Cache(Realm); Dependencies.Cache(Realm);
} }
[SetUp]
public new void Setup() => Schedule(() =>
{
Child = list = new MultiplayerPlaylist
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Size = new Vector2(0.4f, 0.8f)
};
});
[SetUpSteps] [SetUpSteps]
public new void SetUpSteps() public override void SetUpSteps()
{ {
base.SetUpSteps();
AddStep("create list", () =>
{
Child = list = new MultiplayerPlaylist
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Size = new Vector2(0.4f, 0.8f)
};
});
AddStep("import beatmap", () => AddStep("import beatmap", () =>
{ {
beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely(); beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();

View File

@ -46,43 +46,47 @@ namespace osu.Game.Tests.Visual.Multiplayer
beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely(); beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();
} }
[SetUp] public override void SetUpSteps()
public new void Setup() => Schedule(() =>
{ {
AvailabilityTracker.SelectedItem.BindTo(selectedItem); base.SetUpSteps();
importedSet = beatmaps.GetAllUsableBeatmapSets().First(); AddStep("create button", () =>
Beatmap.Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First());
selectedItem.Value = new PlaylistItem(Beatmap.Value.BeatmapInfo)
{ {
RulesetID = Beatmap.Value.BeatmapInfo.Ruleset.OnlineID, AvailabilityTracker.SelectedItem.BindTo(selectedItem);
};
Child = new PopoverContainer importedSet = beatmaps.GetAllUsableBeatmapSets().First();
{ Beatmap.Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First());
RelativeSizeAxes = Axes.Both, selectedItem.Value = new PlaylistItem(Beatmap.Value.BeatmapInfo)
Child = new FillFlowContainer
{ {
AutoSizeAxes = Axes.Both, RulesetID = Beatmap.Value.BeatmapInfo.Ruleset.OnlineID,
Direction = FillDirection.Vertical, };
Children = new Drawable[]
Child = new PopoverContainer
{
RelativeSizeAxes = Axes.Both,
Child = new FillFlowContainer
{ {
spectateButton = new MultiplayerSpectateButton AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{ {
Anchor = Anchor.Centre, spectateButton = new MultiplayerSpectateButton
Origin = Anchor.Centre, {
Size = new Vector2(200, 50), Anchor = Anchor.Centre,
}, Origin = Anchor.Centre,
startControl = new MatchStartControl Size = new Vector2(200, 50),
{ },
Anchor = Anchor.Centre, startControl = new MatchStartControl
Origin = Anchor.Centre, {
Size = new Vector2(200, 50), Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(200, 50),
}
} }
} }
} };
}; });
}); }
[TestCase(MultiplayerRoomState.Open)] [TestCase(MultiplayerRoomState.Open)]
[TestCase(MultiplayerRoomState.WaitingForLoad)] [TestCase(MultiplayerRoomState.WaitingForLoad)]

View File

@ -14,17 +14,21 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
public class TestSceneStarRatingRangeDisplay : OnlinePlayTestScene public class TestSceneStarRatingRangeDisplay : OnlinePlayTestScene
{ {
[SetUp] public override void SetUpSteps()
public new void Setup() => Schedule(() =>
{ {
SelectedRoom.Value = new Room(); base.SetUpSteps();
Child = new StarRatingRangeDisplay AddStep("create display", () =>
{ {
Anchor = Anchor.Centre, SelectedRoom.Value = new Room();
Origin = Anchor.Centre
}; Child = new StarRatingRangeDisplay
}); {
Anchor = Anchor.Centre,
Origin = Anchor.Centre
};
});
}
[Test] [Test]
public void TestRange([Values(0, 2, 3, 4, 6, 7)] double min, [Values(0, 2, 3, 4, 6, 7)] double max) public void TestRange([Values(0, 2, 3, 4, 6, 7)] double min, [Values(0, 2, 3, 4, 6, 7)] double max)

View File

@ -25,17 +25,21 @@ namespace osu.Game.Tests.Visual.Playlists
protected override OnlinePlayTestSceneDependencies CreateOnlinePlayDependencies() => new TestDependencies(); protected override OnlinePlayTestSceneDependencies CreateOnlinePlayDependencies() => new TestDependencies();
[SetUp] public override void SetUpSteps()
public new void Setup() => Schedule(() =>
{ {
SelectedRoom.Value = new Room(); base.SetUpSteps();
Child = settings = new TestRoomSettings(SelectedRoom.Value) AddStep("create overlay", () =>
{ {
RelativeSizeAxes = Axes.Both, SelectedRoom.Value = new Room();
State = { Value = Visibility.Visible }
}; Child = settings = new TestRoomSettings(SelectedRoom.Value)
}); {
RelativeSizeAxes = Axes.Both,
State = { Value = Visibility.Visible }
};
});
}
[Test] [Test]
public void TestButtonEnabledOnlyWithNameAndBeatmap() public void TestButtonEnabledOnlyWithNameAndBeatmap()

View File

@ -15,21 +15,25 @@ namespace osu.Game.Tests.Visual.Playlists
{ {
public class TestScenePlaylistsParticipantsList : OnlinePlayTestScene public class TestScenePlaylistsParticipantsList : OnlinePlayTestScene
{ {
[SetUp] public override void SetUpSteps()
public new void Setup() => Schedule(() =>
{ {
SelectedRoom.Value = new Room { RoomID = { Value = 7 } }; base.SetUpSteps();
for (int i = 0; i < 50; i++) AddStep("create list", () =>
{ {
SelectedRoom.Value.RecentParticipants.Add(new APIUser SelectedRoom.Value = new Room { RoomID = { Value = 7 } };
for (int i = 0; i < 50; i++)
{ {
Username = "peppy", SelectedRoom.Value.RecentParticipants.Add(new APIUser
Statistics = new UserStatistics { GlobalRank = 1234 }, {
Id = 2 Username = "peppy",
}); Statistics = new UserStatistics { GlobalRank = 1234 },
} Id = 2
}); });
}
});
}
[Test] [Test]
public void TestHorizontalLayout() public void TestHorizontalLayout()

View File

@ -3,7 +3,6 @@
#nullable disable #nullable disable
using NUnit.Framework;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
using osu.Game.Tests.Beatmaps; using osu.Game.Tests.Beatmaps;
using osu.Game.Tests.Visual.OnlinePlay; using osu.Game.Tests.Visual.OnlinePlay;
@ -34,13 +33,6 @@ namespace osu.Game.Tests.Visual.Multiplayer
this.joinRoom = joinRoom; this.joinRoom = joinRoom;
} }
[SetUp]
public new void Setup() => Schedule(() =>
{
if (joinRoom)
SelectedRoom.Value = CreateRoom();
});
protected virtual Room CreateRoom() protected virtual Room CreateRoom()
{ {
return new Room return new Room
@ -63,7 +55,12 @@ namespace osu.Game.Tests.Visual.Multiplayer
if (joinRoom) if (joinRoom)
{ {
AddStep("join room", () => RoomManager.CreateRoom(SelectedRoom.Value)); AddStep("join room", () =>
{
SelectedRoom.Value = CreateRoom();
RoomManager.CreateRoom(SelectedRoom.Value);
});
AddUntilStep("wait for room join", () => RoomJoined); AddUntilStep("wait for room join", () => RoomJoined);
} }
} }

View File

@ -4,7 +4,6 @@
#nullable disable #nullable disable
using System; using System;
using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -56,39 +55,43 @@ namespace osu.Game.Tests.Visual.OnlinePlay
return dependencies; return dependencies;
} }
[SetUp] public override void SetUpSteps()
public void Setup() => Schedule(() =>
{ {
// Reset the room dependencies to a fresh state. base.SetUpSteps();
drawableDependenciesContainer.Clear();
dependencies.OnlinePlayDependencies = CreateOnlinePlayDependencies();
drawableDependenciesContainer.AddRange(OnlinePlayDependencies.DrawableComponents);
var handler = OnlinePlayDependencies.RequestsHandler; AddStep("setup dependencies", () =>
// Resolving the BeatmapManager in the test scene will inject the game-wide BeatmapManager, while many test scenes cache their own BeatmapManager instead.
// To get around this, the BeatmapManager is looked up from the dependencies provided to the children of the test scene instead.
var beatmapManager = dependencies.Get<BeatmapManager>();
((DummyAPIAccess)API).HandleRequest = request =>
{ {
try // Reset the room dependencies to a fresh state.
drawableDependenciesContainer.Clear();
dependencies.OnlinePlayDependencies = CreateOnlinePlayDependencies();
drawableDependenciesContainer.AddRange(OnlinePlayDependencies.DrawableComponents);
var handler = OnlinePlayDependencies.RequestsHandler;
// Resolving the BeatmapManager in the test scene will inject the game-wide BeatmapManager, while many test scenes cache their own BeatmapManager instead.
// To get around this, the BeatmapManager is looked up from the dependencies provided to the children of the test scene instead.
var beatmapManager = dependencies.Get<BeatmapManager>();
((DummyAPIAccess)API).HandleRequest = request =>
{ {
return handler.HandleRequest(request, API.LocalUser.Value, beatmapManager); try
} {
catch (ObjectDisposedException) return handler.HandleRequest(request, API.LocalUser.Value, beatmapManager);
{ }
// These requests can be fired asynchronously, but potentially arrive after game components catch (ObjectDisposedException)
// have been disposed (ie. realm in BeatmapManager). {
// This only happens in tests and it's easiest to ignore them for now. // These requests can be fired asynchronously, but potentially arrive after game components
Logger.Log($"Handled {nameof(ObjectDisposedException)} in test request handling"); // have been disposed (ie. realm in BeatmapManager).
return true; // This only happens in tests and it's easiest to ignore them for now.
} Logger.Log($"Handled {nameof(ObjectDisposedException)} in test request handling");
}; return true;
}); }
};
});
}
/// <summary> /// <summary>
/// Creates the room dependencies. Called every <see cref="Setup"/>. /// Creates the room dependencies. Called every <see cref="SetUpSteps"/>.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// Any custom dependencies required for online play sub-classes should be added here. /// Any custom dependencies required for online play sub-classes should be added here.