test: fix shared state, CI-vacuous tests and harness duplication (#2722)
Follow-up to #2721. It fixes how the remaining tests behave and changes no production code. ## CI - Both `dotnet test` steps pass `--filter "Category!=Manual"`. Before this, Manual-tagged tests ran on CI anyway. - The one surviving movement-throttle latency test is the only coverage of burst forgiveness over a full, wrapped history. It loses its Manual tag, so it runs on CI. ## Tests that passed on CI without testing anything - **Corpse and throwing tests.** They relied on tiledata for the weapon `Layer`, so on CI the equip silently failed and they asserted against empty lists. They now set `Layer` explicitly and assert the equip took effect. `TestThrown` also pins its own strength and range values, so a shard retuning SoulGlaive no longer breaks them. - **Healthbar poison rows.** Server.Tests registers no poisons, so every row tested `null`. They now use real poison levels. - **Account packet tests.** The mock accounts reported `Length` 0, so the character-list tests only ever encoded empty slots. They now encode the real characters. - **Pathing and AI tests that only mean something on real Trammel/Felucca terrain** are now guarded with `TileDataRequirement.SkipIfMissing()`: Britain desk and clutter scenes, house footprints (no MultiData on CI) and fingerprints. Tests that are valid on flat blank terrain stay unguarded. (A synthetic tiledata fixture to run these on CI is a planned follow-up.) - **Assertions that couldn't fail now check their claim.** Affected tests include the `DefaultWalker` cache use, cache on/off parity requiring a path, the recorder capability flags, the idle-pet gate, the monthly DST recurrence, the AdvancedSearch `Record.Exception` wrappers, `CanFitItem` with no branch-guarded assert, the Firewall callback, and `Import_NoMap`. The Geometry Parse asserts also now use the same input as their TryParse. ## Shared state Every test that changes process-wide state now restores it, even when an assert fails: - **The clock.** A new `TimerWheelScope` saves and restores `Core._tickCount`, `Core._now` and the timer wheel. `SimulatedClockScope` covers decay tests. - **StepCache settings and caches**, via `StepCacheStateScope`. - **Network state.** The ManualAllowlist, LoginAllowlist, firewall and BanChannel reporters are restored. Global packet handlers are now registered per test and removed afterwards, so they no longer stay registered for later tests. - **Data and config tables.** `ArchiveJournal` statics, `TileData.ItemTable`, `ObjectPropertyList.Enabled`, `Core.Expansion` and the localization table are restored. One `MobileStatusVersion` restore was resetting a different expansion than the one the test changed. - **Entities.** Tests with fixed serials now delete what they create. Fixed mobile serials moved to `World.NewMobile`, because deleting a hard-coded serial could unregister a live entity. - **Collection race.** `SpiralScanTests` no longer clears the spawn cache from a separate collection that could run in parallel with the cache-manager tests. - **Shared statics.** Classes reading shared static allowlists joined the sequential collection. ## Duplication New shared helpers replace copy-pasted harness code: - **Server.Tests:** `PacketAssert.Sends`, used by about 130 packet tests; `TestClientHarness`, `PersistencePipelineScope`, `NetTestHelpers`, `EntityCleanup` and one `TestMulti`. - **UOContent.Tests:** `TimerWheelScope`, which also holds one wraparound-safe `RunFor`/`RunUntil`; `AiTestStubs`, which merges six walker copies and five identical creature stubs; `MobileTestHarness`, `CommandTestHarness` and `TempDirectory`. Dead oracle packet classes are removed. ## Cost | Test | Before | After | |---|---|---| | `VirtualSerialTests` | 1.57s | 2ms (starts near the wrap via reflection instead of drawing ~17.9M serials) | | Event scheduler recurrence loop | 473ms | 1ms | | CrowdSec drain | 517ms | 16ms (event-driven instead of a fixed 500ms wait) | | AuthId tests | 248ms | 99ms (SHA2 except the two GameLogin tests) | | Container cap tests | 5,000 items | 3,449 / 3,277 (one past each protocol cap) | | Bulk removal | 100k children | 20k children | | OPL hash distribution | 60k builds | 10k builds | ## Shard-tuning decoupling - AI assertions read `ReacquireDelay` and `FollowMoveSpeed` instead of hard-coding production tuning. - The guard friendly-fire test uses an `AI_Mage` stub instead of WhiteWyrm. - Argon2 assertions pin the `argon2id` variant and `v=19` but read the cost parameters from the configured hasher. ## Tests | Run | Server.Tests | UOContent.Tests | |---|---|---| | With client files | 812 pass | 1,123 pass | | Without client files (CI simulation) | 800 pass, 12 skip | 1,021 pass, 102 skip | - The UOContent fixture reads `MODERNUO_TEST_DATA_DIR`; Server.Tests reads `MODERNUO_CLIENT_PATH`. - The 15 new UOContent skips are the map-dependent guards above. - Total run time with client files is about 5s, down from about 8s.
This commit is contained in:
parent
79f736aa83
commit
00134cac33
135 changed files with 3164 additions and 4020 deletions
|
|
@ -8,23 +8,16 @@ namespace Server.Tests.Network;
|
|||
[Collection("Sequential Server Tests")]
|
||||
public class PlayerPacketTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(StatLockType.Down, StatLockType.Up, StatLockType.Locked)]
|
||||
public void TestStatLockInfo(StatLockType str, StatLockType intel, StatLockType dex)
|
||||
[Fact]
|
||||
public void TestStatLockInfo()
|
||||
{
|
||||
var m = new Mobile((Serial)0x1);
|
||||
m.DefaultMobileInit();
|
||||
m.StrLock = str;
|
||||
m.IntLock = intel;
|
||||
m.DexLock = dex;
|
||||
m.StrLock = StatLockType.Down;
|
||||
m.IntLock = StatLockType.Up;
|
||||
m.DexLock = StatLockType.Locked;
|
||||
|
||||
var expected = new StatLockInfo(m).Compile();
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendStatLockInfo(m);
|
||||
|
||||
var result = ns.SendBuffer.GetReadSpan();
|
||||
AssertThat.Equal(result, expected);
|
||||
PacketAssert.Sends(new StatLockInfo(m), ns => ns.SendStatLockInfo(m));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
|
@ -33,25 +26,13 @@ public class PlayerPacketTests
|
|||
[InlineData(200)]
|
||||
public void TestChangeUpdateRange(int range)
|
||||
{
|
||||
var expected = new ChangeUpdateRange(range).Compile();
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendChangeUpdateRange((byte)range);
|
||||
|
||||
var result = ns.SendBuffer.GetReadSpan();
|
||||
AssertThat.Equal(result, expected);
|
||||
PacketAssert.Sends(new ChangeUpdateRange(range), ns => ns.SendChangeUpdateRange((byte)range));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestDeathStatus()
|
||||
{
|
||||
var expected = new DeathStatus(false).Compile();
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendDeathStatus();
|
||||
|
||||
var result = ns.SendBuffer.GetReadSpan();
|
||||
AssertThat.Equal(result, expected);
|
||||
PacketAssert.Sends(new DeathStatus(false), ns => ns.SendDeathStatus());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
|
@ -59,13 +40,10 @@ public class PlayerPacketTests
|
|||
[InlineData(0x1000u, null, null, null)]
|
||||
public void TestDisplayProfile(uint serial, string header, string body, string footer)
|
||||
{
|
||||
var expected = new DisplayProfile((Serial)serial, header, body, footer).Compile();
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendDisplayProfile((Serial)serial, header, body, footer);
|
||||
|
||||
var result = ns.SendBuffer.GetReadSpan();
|
||||
AssertThat.Equal(result, expected);
|
||||
PacketAssert.Sends(
|
||||
new DisplayProfile((Serial)serial, header, body, footer),
|
||||
ns => ns.SendDisplayProfile((Serial)serial, header, body, footer)
|
||||
);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
|
@ -73,55 +51,31 @@ public class PlayerPacketTests
|
|||
[InlineData(LRReason.TryToSteal)]
|
||||
public void TestLiftRej(LRReason reason)
|
||||
{
|
||||
var expected = new LiftRej(reason).Compile();
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendLiftReject(reason);
|
||||
|
||||
var result = ns.SendBuffer.GetReadSpan();
|
||||
AssertThat.Equal(result, expected);
|
||||
PacketAssert.Sends(new LiftRej(reason), ns => ns.SendLiftReject(reason));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestLogoutAck()
|
||||
{
|
||||
var expected = new LogoutAck().Compile();
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendLogoutAck();
|
||||
|
||||
var result = ns.SendBuffer.GetReadSpan();
|
||||
AssertThat.Equal(result, expected);
|
||||
PacketAssert.Sends(new LogoutAck(), ns => ns.SendLogoutAck());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1, 2, 3)]
|
||||
[InlineData(4, 5, 6)]
|
||||
[InlineData(0x1234, 0x5678, 0x9ABC)]
|
||||
public void TestWeather(int type, int density, int temp)
|
||||
[InlineData(0xFF, 0x46, 0xEC)]
|
||||
public void TestWeather(byte type, byte density, byte temp)
|
||||
{
|
||||
var expected = new Weather(type, density, temp).Compile();
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendWeather((byte)type, (byte)density, (byte)temp);
|
||||
|
||||
var result = ns.SendBuffer.GetReadSpan();
|
||||
AssertThat.Equal(result, expected);
|
||||
PacketAssert.Sends(new Weather(type, density, temp), ns => ns.SendWeather(type, density, temp));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(100, 1000, 1, 0)]
|
||||
public void TestServerChange(int x, int y, int z, int mapID)
|
||||
[Fact]
|
||||
public void TestServerChange()
|
||||
{
|
||||
var p = new Point3D(x, y, z);
|
||||
var map = Map.Maps[mapID];
|
||||
var expected = new ServerChange(p, map).Compile();
|
||||
var p = new Point3D(100, 1000, 1);
|
||||
var map = Map.Maps[0];
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendServerChange(p, map);
|
||||
|
||||
var result = ns.SendBuffer.GetReadSpan();
|
||||
AssertThat.Equal(result, expected);
|
||||
PacketAssert.Sends(new ServerChange(p, map), ns => ns.SendServerChange(p, map));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
|
@ -130,13 +84,7 @@ public class PlayerPacketTests
|
|||
[InlineData(255)]
|
||||
public void TestSequence(byte num)
|
||||
{
|
||||
var expected = new Sequence(num).Compile();
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendSequence(num);
|
||||
|
||||
var result = ns.SendBuffer.GetReadSpan();
|
||||
AssertThat.Equal(result, expected);
|
||||
PacketAssert.Sends(new Sequence(num), ns => ns.SendSequence(num));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
|
@ -146,37 +94,22 @@ public class PlayerPacketTests
|
|||
[InlineData("https://www.modernuo.com")]
|
||||
public void TestLaunchBrowser(string uri)
|
||||
{
|
||||
var expected = new LaunchBrowser(uri).Compile();
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendLaunchBrowser(uri);
|
||||
|
||||
var result = ns.SendBuffer.GetReadSpan();
|
||||
AssertThat.Equal(result, expected);
|
||||
PacketAssert.Sends(new LaunchBrowser(uri), ns => ns.SendLaunchBrowser(uri));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0x1000u, 1000, 100, 10, 0x2000u, 1125, 125, 5, 0x384, 1024, 25)]
|
||||
public void TestDragEffect(
|
||||
uint srcSerial, int srcX, int srcY, int srcZ,
|
||||
uint trgSerial, int trgX, int trgY, int trgZ,
|
||||
int itemId, int hue, int amount
|
||||
)
|
||||
[Fact]
|
||||
public void TestDragEffect()
|
||||
{
|
||||
var src = new Entity((Serial)srcSerial, new Point3D(srcX, srcY, srcZ), null);
|
||||
var targ = new Entity((Serial)trgSerial, new Point3D(trgX, trgY, trgZ), null);
|
||||
var src = new Entity((Serial)0x1000, new Point3D(1000, 100, 10), null);
|
||||
var targ = new Entity((Serial)0x2000, new Point3D(1125, 125, 5), null);
|
||||
const int itemId = 0x384;
|
||||
const int hue = 1024;
|
||||
const int amount = 25;
|
||||
|
||||
var expected = new DragEffect(src, targ, itemId, hue, amount).Compile();
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendDragEffect(
|
||||
src.Serial, src.Location,
|
||||
targ.Serial, targ.Location,
|
||||
itemId, hue, amount
|
||||
PacketAssert.Sends(
|
||||
new DragEffect(src, targ, itemId, hue, amount),
|
||||
ns => ns.SendDragEffect(src.Serial, src.Location, targ.Serial, targ.Location, itemId, hue, amount)
|
||||
);
|
||||
|
||||
var result = ns.SendBuffer.GetReadSpan();
|
||||
AssertThat.Equal(result, expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
|
@ -184,13 +117,7 @@ public class PlayerPacketTests
|
|||
[InlineData(2, true)]
|
||||
public void TestSeasonChange(int season, bool playSound)
|
||||
{
|
||||
var expected = new SeasonChange(season, playSound).Compile();
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendSeasonChange((byte)season, playSound);
|
||||
|
||||
var result = ns.SendBuffer.GetReadSpan();
|
||||
AssertThat.Equal(result, expected);
|
||||
PacketAssert.Sends(new SeasonChange(season, playSound), ns => ns.SendSeasonChange((byte)season, playSound));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
|
@ -199,13 +126,10 @@ public class PlayerPacketTests
|
|||
[InlineData(0x1024u, "Test Title", true, false)]
|
||||
public void TestDisplayPaperdoll(uint m, string title, bool warmode, bool canLift)
|
||||
{
|
||||
var expected = new DisplayPaperdoll((Serial)m, title, warmode, canLift).Compile();
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendDisplayPaperdoll((Serial)m, title, warmode, canLift);
|
||||
|
||||
var result = ns.SendBuffer.GetReadSpan();
|
||||
AssertThat.Equal(result, expected);
|
||||
PacketAssert.Sends(
|
||||
new DisplayPaperdoll((Serial)m, title, warmode, canLift),
|
||||
ns => ns.SendDisplayPaperdoll((Serial)m, title, warmode, canLift)
|
||||
);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
|
@ -214,13 +138,7 @@ public class PlayerPacketTests
|
|||
[InlineData(MusicName.ValoriaShips)]
|
||||
public void TestPlayMusic(MusicName music)
|
||||
{
|
||||
var expected = new PlayMusic(music).Compile();
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendPlayMusic(music);
|
||||
|
||||
var result = ns.SendBuffer.GetReadSpan();
|
||||
AssertThat.Equal(result, expected);
|
||||
PacketAssert.Sends(new PlayMusic(music), ns => ns.SendPlayMusic(music));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
|
@ -228,41 +146,23 @@ public class PlayerPacketTests
|
|||
[InlineData(100, 10, "Some more text")]
|
||||
public void TestScrollMessage(int type, int tip, string text)
|
||||
{
|
||||
var expected = new ScrollMessage(type, tip, text).Compile();
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendScrollMessage(type, tip ,text);
|
||||
|
||||
var result = ns.SendBuffer.GetReadSpan();
|
||||
AssertThat.Equal(result, expected);
|
||||
PacketAssert.Sends(new ScrollMessage(type, tip, text), ns => ns.SendScrollMessage(type, tip, text));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(14, 10, 05)]
|
||||
public void TestCurrentTime(int hour, int minute, int second)
|
||||
[Fact]
|
||||
public void TestCurrentTime()
|
||||
{
|
||||
var date = new DateTime(2020, 1, 1, hour, minute, second);
|
||||
var expected = new CurrentTime(date).Compile();
|
||||
var date = new DateTime(2020, 1, 1, 14, 10, 5);
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendCurrentTime(date);
|
||||
|
||||
var result = ns.SendBuffer.GetReadSpan();
|
||||
AssertThat.Equal(result, expected);
|
||||
PacketAssert.Sends(new CurrentTime(date), ns => ns.SendCurrentTime(date));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1000, 10, 1)]
|
||||
public void TestPathfindMessage(int x, int y, int z)
|
||||
[Fact]
|
||||
public void TestPathfindMessage()
|
||||
{
|
||||
var p = new Point3D(x, y, z);
|
||||
var expected = new PathfindMessage(p).Compile();
|
||||
var p = new Point3D(1000, 10, 1);
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendPathfindMessage(p);
|
||||
|
||||
var result = ns.SendBuffer.GetReadSpan();
|
||||
AssertThat.Equal(result, expected);
|
||||
PacketAssert.Sends(new PathfindMessage(p), ns => ns.SendPathfindMessage(p));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
|
@ -271,27 +171,17 @@ public class PlayerPacketTests
|
|||
[InlineData(100)]
|
||||
public void TestPingAck(byte ping)
|
||||
{
|
||||
var expected = new PingAck(ping).Compile();
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendPingAck(ping);
|
||||
|
||||
var result = ns.SendBuffer.GetReadSpan();
|
||||
AssertThat.Equal(result, expected);
|
||||
PacketAssert.Sends(new PingAck(ping), ns => ns.SendPingAck(ping));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0xFF01)]
|
||||
public void TestDisplayHuePicker(int itemID)
|
||||
[Fact]
|
||||
public void TestDisplayHuePicker()
|
||||
{
|
||||
var huePicker = new HuePicker(itemID);
|
||||
var huePicker = new HuePicker(0xFF01);
|
||||
|
||||
var expected = new DisplayHuePicker(huePicker).Compile();
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendDisplayHuePicker(huePicker.Serial, huePicker.ItemID);
|
||||
|
||||
var result = ns.SendBuffer.GetReadSpan();
|
||||
AssertThat.Equal(result, expected);
|
||||
PacketAssert.Sends(
|
||||
new DisplayHuePicker(huePicker),
|
||||
ns => ns.SendDisplayHuePicker(huePicker.Serial, huePicker.ItemID)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue