fix: Fixes flaky tests, formatting, and sequential testing. (#2168)

This commit is contained in:
Kamron Batman 2025-04-30 16:42:38 -07:00 committed by GitHub
parent 415c7a6bfd
commit 7dbfc9d161
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
60 changed files with 1304 additions and 1289 deletions

View file

@ -1,12 +1,13 @@
using System;
using System.Reflection;
using Xunit;
namespace Server.Tests;
internal class ServerFixture : IDisposable
[CollectionDefinition("Sequential Server Tests", DisableParallelization = true)]
public class ServerFixture : ICollectionFixture<ServerFixture>, IDisposable
{
// Global setup
static ServerFixture()
public ServerFixture()
{
Core.ApplicationAssembly = Assembly.GetExecutingAssembly(); // Server.Tests.dll

View file

@ -1,34 +1,33 @@
namespace Server
namespace Server.Tests;
public static class TestMapDefinitions
{
public static class TestMapDefinitions
public static void ConfigureTestMapDefinitions()
{
public static void ConfigureTestMapDefinitions()
{
RegisterMap(0, 0, 0, 7168, 4096, 4, "Felucca", MapRules.FeluccaRules);
RegisterMap(1, 1, 1, 7168, 4096, 0, "Trammel", MapRules.TrammelRules);
RegisterMap(2, 2, 2, 2304, 1600, 1, "Ilshenar", MapRules.TrammelRules);
RegisterMap(3, 3, 3, 2560, 2048, 1, "Malas", MapRules.TrammelRules);
RegisterMap(4, 4, 4, 1448, 1448, 1, "Tokuno", MapRules.TrammelRules);
RegisterMap(5, 5, 5, 1280, 4096, 1, "TerMur", MapRules.TrammelRules);
RegisterMap(0, 0, 0, 7168, 4096, 4, "Felucca", MapRules.FeluccaRules);
RegisterMap(1, 1, 1, 7168, 4096, 0, "Trammel", MapRules.TrammelRules);
RegisterMap(2, 2, 2, 2304, 1600, 1, "Ilshenar", MapRules.TrammelRules);
RegisterMap(3, 3, 3, 2560, 2048, 1, "Malas", MapRules.TrammelRules);
RegisterMap(4, 4, 4, 1448, 1448, 1, "Tokuno", MapRules.TrammelRules);
RegisterMap(5, 5, 5, 1280, 4096, 1, "TerMur", MapRules.TrammelRules);
RegisterMap(0x7F, 0x7F, 0x7F, Map.SectorSize, Map.SectorSize, 1, "Internal", MapRules.Internal);
}
RegisterMap(0x7F, 0x7F, 0x7F, Map.SectorSize, Map.SectorSize, 1, "Internal", MapRules.Internal);
}
private static void RegisterMap(
int mapIndex,
int mapID,
int fileIndex,
int width,
int height,
int season,
string name,
MapRules rules
)
{
var newMap = new Map(mapID, mapIndex, fileIndex, width, height, season, name, rules);
private static void RegisterMap(
int mapIndex,
int mapID,
int fileIndex,
int width,
int height,
int season,
string name,
MapRules rules
)
{
var newMap = new Map(mapID, mapIndex, fileIndex, width, height, season, name, rules);
Map.Maps[mapIndex] = newMap;
Map.AllMaps.Add(newMap);
}
Map.Maps[mapIndex] = newMap;
Map.AllMaps.Add(newMap);
}
}

View file

@ -1,9 +0,0 @@
using Xunit;
namespace Server.Tests
{
[CollectionDefinition("Sequential Tests", DisableParallelization = true)]
public class SequentialTestCollectionDefinition
{
}
}

View file

@ -4,7 +4,7 @@ using Xunit;
namespace Server.Tests.Tests.Buffers;
[Collection("Sequential Tests")]
[Collection("Sequential Server Tests")]
public class STArrayPoolTests
{
[Theory]

View file

@ -3,7 +3,7 @@ using Xunit;
namespace Server.Tests.Buffers;
[Collection("Sequential Tests")]
[Collection("Sequential Server Tests")]
public class ValueStringBuilderTests
{
[Theory]

View file

@ -2,7 +2,7 @@ using Xunit;
namespace Server.Tests.Network;
[Collection("Sequential Tests")]
[Collection("Sequential Server Tests")]
public class ClientVersionTests
{
[Theory]

View file

@ -3,7 +3,8 @@ using Xunit;
namespace Server.Tests;
public sealed class WorldLocationTests : IClassFixture<ServerFixture>
[Collection("Sequential Server Tests")]
public sealed class WorldLocationTests
{
private static Map CreateMap(string name) => new(0, 0, 0, 1, 1, 0, name, MapRules.Internal);

View file

@ -5,7 +5,8 @@ using Xunit;
namespace Server.Tests;
public class ContainerTests : IClassFixture<ServerFixture>
[Collection("Sequential Server Tests")]
public class ContainerTests
{
[Fact]
public void TestFindItemsByType()

View file

@ -2,7 +2,7 @@ using Xunit;
namespace Server.Tests;
[Collection("Sequential Tests")]
[Collection("Sequential Server Tests")]
public class LocalizationEntryTests
{
[Fact]

View file

@ -7,7 +7,8 @@ using Xunit;
namespace Server.Tests.Network;
public class AccountPacketTests : IClassFixture<ServerFixture>
[Collection("Sequential Server Tests")]
public class AccountPacketTests
{
private class MockedAccount : IAccount
{

View file

@ -4,8 +4,8 @@ using Xunit;
namespace Server.Tests.Network
{
[Collection("Sequential Tests")]
public class ContainerPacketTests : IClassFixture<ServerFixture>
[Collection("Sequential Server Tests")]
public class ContainerPacketTests
{
[Fact]

View file

@ -3,7 +3,8 @@ using Xunit;
namespace Server.Tests.Network
{
public class DamagePacketTests : IClassFixture<ServerFixture>
[Collection("Sequential Server Tests")]
public class DamagePacketTests
{
[Theory, InlineData(10), InlineData(-5), InlineData(1024)]
public void TestDamagePacketOld(int inputAmount)

View file

@ -4,7 +4,8 @@ using Xunit;
namespace Server.Tests.Network
{
public class EquipmentPacketTests : IClassFixture<ServerFixture>
[Collection("Sequential Server Tests")]
public class EquipmentPacketTests
{
[Theory]
[InlineData(null, false)]

View file

@ -3,8 +3,8 @@ using Xunit;
namespace Server.Tests.Network;
[Collection("Sequential Tests")]
public class GumpPacketTests : IClassFixture<ServerFixture>
[Collection("Sequential Server Tests")]
public class GumpPacketTests
{
[Theory]
[InlineData(100, 10)]

View file

@ -3,7 +3,8 @@ using Xunit;
namespace Server.Tests.Network
{
public class ItemPacketTests : IClassFixture<ServerFixture>
[Collection("Sequential Server Tests")]
public class ItemPacketTests
{
[Fact]
public void TestWorldItemPacket()

View file

@ -3,7 +3,8 @@ using Xunit;
namespace Server.Tests.Network
{
public class MapPatchesTests : IClassFixture<ServerFixture>
[Collection("Sequential Server Tests")]
public class MapPatchesTests
{
[Fact]
public void TestMapPatches()

View file

@ -27,8 +27,8 @@ namespace Server.Tests.Network
}
}
[Collection("Sequential Tests")]
public class MenuPacketTests : IClassFixture<ServerFixture>
[Collection("Sequential Server Tests")]
public class MenuPacketTests
{
[Fact]
public void TestDisplayItemListMenu()

View file

@ -3,8 +3,8 @@ using Xunit;
namespace Server.Tests.Network;
[Collection("Sequential Tests")]
public class MobilePacketTests : IClassFixture<ServerFixture>
[Collection("Sequential Server Tests")]
public class MobilePacketTests
{
[Fact]
public void TestDeathAnimation()

View file

@ -3,7 +3,8 @@ using Xunit;
namespace Server.Tests.Network
{
public class MovementPacketTests : IClassFixture<ServerFixture>
[Collection("Sequential Server Tests")]
public class MovementPacketTests
{
[Theory]
[InlineData(0)]

View file

@ -5,8 +5,8 @@ using Xunit;
namespace Server.Tests.Network
{
[Collection("Sequential Tests")]
public class PlayerPacketTests : IClassFixture<ServerFixture>
[Collection("Sequential Server Tests")]
public class PlayerPacketTests
{
[Theory]
[InlineData(StatLockType.Down, StatLockType.Up, StatLockType.Locked)]

View file

@ -4,7 +4,8 @@ using Xunit;
namespace Server.Tests.Network
{
public class SecureTradePacketTests : IClassFixture<ServerFixture>
[Collection("Sequential Server Tests")]
public class SecureTradePacketTests
{
[Theory]
[InlineData("short-name")]

View file

@ -5,8 +5,8 @@ using Xunit;
namespace Server.Tests.Network
{
[Collection("Sequential Tests")]
public class VendorBuyPacketTests : IClassFixture<ServerFixture>
[Collection("Sequential Server Tests")]
public class VendorBuyPacketTests
{
[Theory]
[InlineData(ProtocolChanges.None)]

View file

@ -5,8 +5,8 @@ using Xunit;
namespace Server.Tests.Network
{
[Collection("Sequential Tests")]
public class VendorSellPacketTests : IClassFixture<ServerFixture>
[Collection("Sequential Server Tests")]
public class VendorSellPacketTests
{
[Fact]
public void TestVendorSellList()

View file

@ -2,40 +2,40 @@ using Server.Network;
using Server.Tests.Network;
using Xunit;
namespace Server.Tests
namespace Server.Tests;
[Collection("Sequential Server Tests")]
public class VirtualHairPacketTests
{
public class VirtualHairPacketTests: IClassFixture<ServerFixture>
[Fact]
public void TestSendVirtualHairUpdate()
{
[Fact]
public void TestSendVirtualHairUpdate()
{
var m = new Mobile((Serial)0x1024u);
m.DefaultMobileInit();
m.HairHue = 0x1000;
m.HairItemID = 0x2000;
var m = new Mobile((Serial)0x1024u);
m.DefaultMobileInit();
m.HairHue = 0x1000;
m.HairItemID = 0x2000;
var expected = new HairEquipUpdate(m).Compile();
var expected = new HairEquipUpdate(m).Compile();
var ns = PacketTestUtilities.CreateTestNetState();
ns.SendHairEquipUpdatePacket(m, (uint)m.Hair.VirtualSerial, m.Hair.ItemId, m.Hair.Hue, Layer.Hair);
var ns = PacketTestUtilities.CreateTestNetState();
ns.SendHairEquipUpdatePacket(m, (uint)m.Hair.VirtualSerial, m.Hair.ItemId, m.Hair.Hue, Layer.Hair);
var result = ns.SendPipe.Reader.AvailableToRead();
AssertThat.Equal(result, expected);
}
var result = ns.SendPipe.Reader.AvailableToRead();
AssertThat.Equal(result, expected);
}
[Fact]
public void TestSendRemoveVirtualHair()
{
var m = new Mobile((Serial)0x1024u);
m.DefaultMobileInit();
[Fact]
public void TestSendRemoveVirtualHair()
{
var m = new Mobile((Serial)0x1024u);
m.DefaultMobileInit();
var expected = new RemoveHair(m).Compile();
var expected = new RemoveHair(m).Compile();
var ns = PacketTestUtilities.CreateTestNetState();
ns.SendRemoveHairPacket((uint) m.Hair.VirtualSerial);
var ns = PacketTestUtilities.CreateTestNetState();
ns.SendRemoveHairPacket((uint) m.Hair.VirtualSerial);
var result = ns.SendPipe.Reader.AvailableToRead();
AssertThat.Equal(result, expected);
}
var result = ns.SendPipe.Reader.AvailableToRead();
AssertThat.Equal(result, expected);
}
}

View file

@ -8,7 +8,8 @@ using Xunit;
namespace Server.Tests;
public class TypeConverterTests : IClassFixture<ServerFixture>
[Collection("Sequential Server Tests")]
public class TypeConverterTests
{
[Fact]
public void TestReadAfterWrite()

View file

@ -3,8 +3,8 @@ using Xunit;
namespace Server.Tests;
[Collection("Sequential Tests")]
public class TimerTests : IClassFixture<ServerFixture>
[Collection("Sequential Server Tests")]
public class TimerTests
{
[Theory]
[InlineData(0L, 8L)]

View file

@ -4,7 +4,7 @@ using Xunit;
namespace Server.Tests;
[Collection("Sequential Tests")]
[Collection("Sequential Server Tests")]
public class TestStringHelpers
{
[Theory]

View file

@ -2,8 +2,8 @@ using Xunit;
namespace Server.Tests;
[Collection("Sequential Tests")]
public class VirtualSerialTests : IClassFixture<ServerFixture>
[Collection("Sequential Server Tests")]
public class VirtualSerialTests
{
[Fact]
public void TestNewVirtualGetsAndRollover()