Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix occasionally ChatOverlay test failures due to RNG usage #29365

Merged
merged 3 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions osu.Game.Tests/Resources/TestResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ public static string GetTestBeatmapForImport(bool virtualTrack = false)

private static string getTempFilename() => temp_storage.GetFullPath(Guid.NewGuid() + ".osz");

private static int importId;
private static int testId = 1;

/// <summary>
/// Get a unique int value which is incremented each call.
/// </summary>
public static int GetNextTestID() => Interlocked.Increment(ref testId);

/// <summary>
/// Create a test beatmap set model.
Expand All @@ -88,7 +93,7 @@ public static BeatmapSetInfo CreateTestBeatmapSetInfo(int? difficultyCount = nul

RulesetInfo getRuleset() => rulesets?[j++ % rulesets.Length];

int setId = Interlocked.Increment(ref importId);
int setId = GetNextTestID();

var metadata = new BeatmapMetadata
{
Expand Down
4 changes: 2 additions & 2 deletions osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ public void TestLobbyEvents()

private void addRandomPlayer()
{
int randomUser = RNG.Next(200000, 500000);
multiplayerClient.AddUser(new APIUser { Id = randomUser, Username = $"user {randomUser}" });
int id = TestResources.GetNextTestID();
multiplayerClient.AddUser(new APIUser { Id = id, Username = $"user {id}" });
}

private void removeLastUser()
Expand Down
8 changes: 4 additions & 4 deletions osu.Game.Tests/Visual/Online/TestSceneChannelList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Chat;
using osu.Game.Overlays;
using osu.Game.Overlays.Chat.ChannelList;
using osu.Game.Overlays.Chat.Listing;
using osu.Game.Tests.Resources;

namespace osu.Game.Tests.Visual.Online
{
Expand Down Expand Up @@ -160,7 +160,7 @@ public void TestVisual()

private Channel createRandomPublicChannel()
{
int id = RNG.Next(0, 10000);
int id = TestResources.GetNextTestID();
return new Channel
{
Name = $"#channel-{id}",
Expand All @@ -171,7 +171,7 @@ private Channel createRandomPublicChannel()

private Channel createRandomPrivateChannel()
{
int id = RNG.Next(0, 10000);
int id = TestResources.GetNextTestID();
return new Channel(new APIUser
{
Id = id,
Expand All @@ -181,7 +181,7 @@ private Channel createRandomPrivateChannel()

private Channel createRandomAnnounceChannel()
{
int id = RNG.Next(0, 10000);
int id = TestResources.GetNextTestID();
return new Channel
{
Name = $"Announce {id}",
Expand Down
7 changes: 4 additions & 3 deletions osu.Game.Tests/Visual/Online/TestSceneChatOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
using osu.Framework.Input;
using osu.Framework.Logging;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Configuration;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
Expand All @@ -33,6 +32,7 @@
using osuTK;
using osuTK.Input;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Tests.Resources;

namespace osu.Game.Tests.Visual.Online
{
Expand Down Expand Up @@ -122,7 +122,7 @@ public void SetUpSteps()
return true;

case PostMessageRequest postMessage:
postMessage.TriggerSuccess(new Message(RNG.Next(0, 10000000))
postMessage.TriggerSuccess(new Message(TestResources.GetNextTestID())
{
Content = postMessage.Message.Content,
ChannelId = postMessage.Message.ChannelId,
Expand Down Expand Up @@ -719,7 +719,8 @@ private List<Message> createChannelMessages(Channel channel)

private Channel createPrivateChannel()
{
int id = RNG.Next(0, DummyAPIAccess.DUMMY_USER_ID - 1);
int id = TestResources.GetNextTestID();

return new Channel(new APIUser
{
Id = id,
Expand Down
Loading