1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 15:33:05 +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;
[SetUp]
public new void Setup() => Schedule(() =>
public override void SetUpSteps()
{
SelectedRoom.Value = new Room
{
Name = { Value = "test room" },
Host =
{
Value = new APIUser
{
Id = 2,
Username = "peppy",
}
}
};
base.SetUpSteps();
Child = list = new DrawableRoomParticipantsList
AddStep("create list", () =>
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
NumberOfCircles = 4
};
});
SelectedRoom.Value = new Room
{
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]
public void TestCircleCountNearLimit()

View File

@ -25,23 +25,27 @@ namespace osu.Game.Tests.Visual.Multiplayer
private RoomsContainer container;
[SetUp]
public new void Setup() => Schedule(() =>
public override void SetUpSteps()
{
Child = new PopoverContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Width = 0.5f,
base.SetUpSteps();
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]
public void TestBasicListChanges()

View File

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

View File

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

View File

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

View File

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

View File

@ -42,21 +42,22 @@ namespace osu.Game.Tests.Visual.Multiplayer
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]
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", () =>
{
beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();

View File

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

View File

@ -14,17 +14,21 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
public class TestSceneStarRatingRangeDisplay : OnlinePlayTestScene
{
[SetUp]
public new void Setup() => Schedule(() =>
public override void SetUpSteps()
{
SelectedRoom.Value = new Room();
base.SetUpSteps();
Child = new StarRatingRangeDisplay
AddStep("create display", () =>
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre
};
});
SelectedRoom.Value = new Room();
Child = new StarRatingRangeDisplay
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre
};
});
}
[Test]
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();
[SetUp]
public new void Setup() => Schedule(() =>
public override void SetUpSteps()
{
SelectedRoom.Value = new Room();
base.SetUpSteps();
Child = settings = new TestRoomSettings(SelectedRoom.Value)
AddStep("create overlay", () =>
{
RelativeSizeAxes = Axes.Both,
State = { Value = Visibility.Visible }
};
});
SelectedRoom.Value = new Room();
Child = settings = new TestRoomSettings(SelectedRoom.Value)
{
RelativeSizeAxes = Axes.Both,
State = { Value = Visibility.Visible }
};
});
}
[Test]
public void TestButtonEnabledOnlyWithNameAndBeatmap()

View File

@ -15,21 +15,25 @@ namespace osu.Game.Tests.Visual.Playlists
{
public class TestScenePlaylistsParticipantsList : OnlinePlayTestScene
{
[SetUp]
public new void Setup() => Schedule(() =>
public override void SetUpSteps()
{
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",
Statistics = new UserStatistics { GlobalRank = 1234 },
Id = 2
});
}
});
SelectedRoom.Value.RecentParticipants.Add(new APIUser
{
Username = "peppy",
Statistics = new UserStatistics { GlobalRank = 1234 },
Id = 2
});
}
});
}
[Test]
public void TestHorizontalLayout()

View File

@ -3,7 +3,6 @@
#nullable disable
using NUnit.Framework;
using osu.Game.Online.Rooms;
using osu.Game.Tests.Beatmaps;
using osu.Game.Tests.Visual.OnlinePlay;
@ -34,13 +33,6 @@ namespace osu.Game.Tests.Visual.Multiplayer
this.joinRoom = joinRoom;
}
[SetUp]
public new void Setup() => Schedule(() =>
{
if (joinRoom)
SelectedRoom.Value = CreateRoom();
});
protected virtual Room CreateRoom()
{
return new Room
@ -63,7 +55,12 @@ namespace osu.Game.Tests.Visual.Multiplayer
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);
}
}

View File

@ -4,7 +4,6 @@
#nullable disable
using System;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
@ -56,39 +55,43 @@ namespace osu.Game.Tests.Visual.OnlinePlay
return dependencies;
}
[SetUp]
public void Setup() => Schedule(() =>
public override void SetUpSteps()
{
// Reset the room dependencies to a fresh state.
drawableDependenciesContainer.Clear();
dependencies.OnlinePlayDependencies = CreateOnlinePlayDependencies();
drawableDependenciesContainer.AddRange(OnlinePlayDependencies.DrawableComponents);
base.SetUpSteps();
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 =>
AddStep("setup dependencies", () =>
{
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);
}
catch (ObjectDisposedException)
{
// These requests can be fired asynchronously, but potentially arrive after game components
// have been disposed (ie. realm in BeatmapManager).
// 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;
}
};
});
try
{
return handler.HandleRequest(request, API.LocalUser.Value, beatmapManager);
}
catch (ObjectDisposedException)
{
// These requests can be fired asynchronously, but potentially arrive after game components
// have been disposed (ie. realm in BeatmapManager).
// 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>
/// Creates the room dependencies. Called every <see cref="Setup"/>.
/// Creates the room dependencies. Called every <see cref="SetUpSteps"/>.
/// </summary>
/// <remarks>
/// Any custom dependencies required for online play sub-classes should be added here.