1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 17:23:22 +08:00

Make ID retrieval global to all tests and fix multiple other usages

This commit is contained in:
Dean Herbert 2024-08-09 17:46:10 +09:00
parent 18c80870d8
commit c8a7727199
No known key found for this signature in database
4 changed files with 16 additions and 14 deletions

View File

@ -73,7 +73,12 @@ namespace osu.Game.Tests.Resources
private static string getTempFilename() => temp_storage.GetFullPath(Guid.NewGuid() + ".osz"); 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> /// <summary>
/// Create a test beatmap set model. /// Create a test beatmap set model.
@ -88,7 +93,7 @@ namespace osu.Game.Tests.Resources
RulesetInfo getRuleset() => rulesets?[j++ % rulesets.Length]; RulesetInfo getRuleset() => rulesets?[j++ % rulesets.Length];
int setId = Interlocked.Increment(ref importId); int setId = GetNextTestID();
var metadata = new BeatmapMetadata var metadata = new BeatmapMetadata
{ {

View File

@ -139,8 +139,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
private void addRandomPlayer() private void addRandomPlayer()
{ {
int randomUser = RNG.Next(200000, 500000); int id = TestResources.GetNextTestID();
multiplayerClient.AddUser(new APIUser { Id = randomUser, Username = $"user {randomUser}" }); multiplayerClient.AddUser(new APIUser { Id = id, Username = $"user {id}" });
} }
private void removeLastUser() private void removeLastUser()

View File

@ -9,13 +9,13 @@ using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Chat; using osu.Game.Online.Chat;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Overlays.Chat.ChannelList; using osu.Game.Overlays.Chat.ChannelList;
using osu.Game.Overlays.Chat.Listing; using osu.Game.Overlays.Chat.Listing;
using osu.Game.Tests.Resources;
namespace osu.Game.Tests.Visual.Online namespace osu.Game.Tests.Visual.Online
{ {
@ -160,7 +160,7 @@ namespace osu.Game.Tests.Visual.Online
private Channel createRandomPublicChannel() private Channel createRandomPublicChannel()
{ {
int id = RNG.Next(0, 10000); int id = TestResources.GetNextTestID();
return new Channel return new Channel
{ {
Name = $"#channel-{id}", Name = $"#channel-{id}",
@ -171,7 +171,7 @@ namespace osu.Game.Tests.Visual.Online
private Channel createRandomPrivateChannel() private Channel createRandomPrivateChannel()
{ {
int id = RNG.Next(0, 10000); int id = TestResources.GetNextTestID();
return new Channel(new APIUser return new Channel(new APIUser
{ {
Id = id, Id = id,
@ -181,7 +181,7 @@ namespace osu.Game.Tests.Visual.Online
private Channel createRandomAnnounceChannel() private Channel createRandomAnnounceChannel()
{ {
int id = RNG.Next(0, 10000); int id = TestResources.GetNextTestID();
return new Channel return new Channel
{ {
Name = $"Announce {id}", Name = $"Announce {id}",

View File

@ -32,6 +32,7 @@ using osu.Game.Overlays.Chat.ChannelList;
using osuTK; using osuTK;
using osuTK.Input; using osuTK.Input;
using osu.Game.Graphics.UserInterfaceV2; using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Tests.Resources;
namespace osu.Game.Tests.Visual.Online namespace osu.Game.Tests.Visual.Online
{ {
@ -121,7 +122,7 @@ namespace osu.Game.Tests.Visual.Online
return true; return true;
case PostMessageRequest postMessage: case PostMessageRequest postMessage:
postMessage.TriggerSuccess(new Message(getNextTestID()) postMessage.TriggerSuccess(new Message(TestResources.GetNextTestID())
{ {
Content = postMessage.Message.Content, Content = postMessage.Message.Content,
ChannelId = postMessage.Message.ChannelId, ChannelId = postMessage.Message.ChannelId,
@ -718,7 +719,7 @@ namespace osu.Game.Tests.Visual.Online
private Channel createPrivateChannel() private Channel createPrivateChannel()
{ {
int id = getNextTestID(); int id = TestResources.GetNextTestID();
return new Channel(new APIUser return new Channel(new APIUser
{ {
@ -739,10 +740,6 @@ namespace osu.Game.Tests.Visual.Online
}; };
} }
private static int testId = DummyAPIAccess.DUMMY_USER_ID + 1;
private static int getNextTestID() => Interlocked.Increment(ref testId);
private partial class TestChatOverlay : ChatOverlay private partial class TestChatOverlay : ChatOverlay
{ {
public bool SlowLoading { get; set; } public bool SlowLoading { get; set; }