## Summary Many tests proved a specific change when it landed but don't need to run on every CI build forever. This removes **202 test methods and 9 files: 313 test cases, 2,247 → 1,934**. UOContent.Tests drops from about 14s to about 5s locally. Removed: - **Tautologies.** Asserting a constant, a constructor readback or a trivial getter, or testing BCL behavior. - **Exact duplicates** of a surviving test on the same code path. - **Obsolete regressions** whose failure can no longer be expressed. - **Game-content values** shard owners customize (era drop rates, loot and skill tables, single-creature tuning). Each customization would otherwise force a test fix. ## How it was decided 1. Every test was classified, with a reason, by a per-shard sweep over all 287 test files. 2. Each proposed deletion was then checked by a second, adversarial reviewer against the surviving tests and the production code. 3. Anything that was the only coverage of a separate code path was **kept**, even where it looked like a duplicate. Examples: the unsigned `SpanReader`/`SpanWriter` methods, the at-location versus bounds enumerators, null-map enumerables, the security filters, archive-journal state transitions. About 130 proposed deletions were rejected this way. Whole files removed: - `FishingTests`, apart from 3 tests: the map-edge scan, serpent cleanup, and SOS chest consumption. The SOS test now stops at the first chest instead of measuring a catch rate. The multi-million-cast rate simulations are gone. - `LordOaksTests` and `MeerEnragedTests` (single-creature tests). - `AutoArchiveHelperTests`, `JsonDiscoverableTypeAttributeTests`, `DecimalSerializationTests` and `EnumConversionTests` (tautologies, or tests of their own local helpers). - `NetworkStatsTests`. - `MigratedDataLoadTests` (a subset of `AllSpawnFilesLoadTests`). - `SpawnerFixtureCapture`: a capture tool, not a test, and its `version == 12` assert can no longer pass. The `.bin` fixtures it produced stay. ## Tests - Server.Tests: 811 pass. - UOContent.Tests: 1,123 pass. A follow-up PR, stacked on this one, fixes how the remaining tests behave: shared state, CI-vacuous tests, harness duplication.
435 lines
13 KiB
C#
435 lines
13 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Server.Accounting;
|
|
using Server.Network;
|
|
using Server.Tests.Network;
|
|
using Xunit;
|
|
|
|
namespace Server.Tests.Maps;
|
|
|
|
[Collection("Sequential Server Tests")]
|
|
public class ClientEnumeratorTests
|
|
{
|
|
[Fact]
|
|
public void ClientEnumerator_FiltersByBoundsAndOrder()
|
|
{
|
|
var map = Map.Felucca;
|
|
var rect = new Rectangle2D(100, 100, 32, 32);
|
|
|
|
var clients = new (NetState, Mobile)[3];
|
|
try
|
|
{
|
|
clients[0] = CreateClientWithMobile(map, new Point3D(105, 105, 0));
|
|
clients[1] = CreateClientWithMobile(map, new Point3D(130, 130, 0));
|
|
clients[2] = CreateClientWithMobile(map, new Point3D(90, 90, 0));
|
|
|
|
var found = new List<NetState>();
|
|
foreach (var ns in map.GetClientsInBounds(rect))
|
|
{
|
|
found.Add(ns);
|
|
}
|
|
|
|
Assert.Equal(2, found.Count);
|
|
Assert.All(found, ns => Assert.True(rect.Contains(ns.Mobile.Location)));
|
|
Assert.Equal(new[] { clients[0].Item1, clients[1].Item1 }, found);
|
|
}
|
|
finally
|
|
{
|
|
DeleteAll(clients);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void ClientEnumerator_SkipsNullMobiles()
|
|
{
|
|
var map = Map.Felucca;
|
|
var rect = new Rectangle2D(200, 200, 16, 16);
|
|
|
|
var clients = new (NetState, Mobile)[3];
|
|
try
|
|
{
|
|
clients[0] = CreateClientWithMobile(map, new Point3D(205, 205, 0));
|
|
clients[1] = CreateClientWithMobile(map, new Point3D(206, 205, 0));
|
|
clients[2] = CreateClientWithMobile(map, new Point3D(207, 205, 0));
|
|
|
|
// Remove the mobile from the second client
|
|
clients[1].Item2.Delete();
|
|
clients[1].Item1.Mobile = null;
|
|
|
|
var found = new List<NetState>();
|
|
foreach (var ns in map.GetClientsInBounds(rect))
|
|
{
|
|
found.Add(ns);
|
|
}
|
|
|
|
Assert.Equal(2, found.Count);
|
|
Assert.Equal(new[] { clients[0].Item1, clients[2].Item1 }, found);
|
|
}
|
|
finally
|
|
{
|
|
DeleteAll(clients);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void ClientEnumerator_RespectsMakeBoundsInclusiveFlag()
|
|
{
|
|
var map = Map.Felucca;
|
|
var rect = new Rectangle2D(300, 300, 1, 1);
|
|
|
|
var clients = new (NetState, Mobile)[1];
|
|
try
|
|
{
|
|
clients[0] = CreateClientWithMobile(map, new Point3D(301, 301, 0));
|
|
|
|
var enumerator = map.GetClientsInBounds(rect, makeBoundsInclusive: true).GetEnumerator();
|
|
|
|
Assert.True(enumerator.MoveNext());
|
|
Assert.Equal(clients[0].Item1, enumerator.Current);
|
|
}
|
|
finally
|
|
{
|
|
DeleteAll(clients);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void ClientEnumerator_MapNullYieldsEmpty()
|
|
{
|
|
var enumerator = new Map.ClientBoundsEnumerable(null, Rectangle2D.Empty, false).GetEnumerator();
|
|
Assert.False(enumerator.MoveNext());
|
|
}
|
|
|
|
[Fact]
|
|
public void ClientEnumerator_ThrowsOnVersionChange()
|
|
{
|
|
var map = Map.Felucca;
|
|
var rect = new Rectangle2D(400, 400, 16, 16);
|
|
|
|
var clients = new[]
|
|
{
|
|
CreateClientWithMobile(map, new Point3D(405, 405, 0)),
|
|
CreateClientWithMobile(map, new Point3D(406, 405, 0))
|
|
};
|
|
|
|
try
|
|
{
|
|
var enumerator = map.GetClientsInBounds(rect).GetEnumerator();
|
|
Assert.True(enumerator.MoveNext());
|
|
|
|
clients[1].Item2.Delete();
|
|
|
|
// Ref structs cannot be captured in lambdas, so we test the exception directly
|
|
var exceptionThrown = false;
|
|
try
|
|
{
|
|
enumerator.MoveNext();
|
|
}
|
|
catch (InvalidOperationException)
|
|
{
|
|
exceptionThrown = true;
|
|
}
|
|
|
|
Assert.True(exceptionThrown, "Expected InvalidOperationException when collection version changes");
|
|
}
|
|
finally
|
|
{
|
|
DeleteAll(clients);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void ClientEnumerator_StepsAcrossSectors()
|
|
{
|
|
var map = Map.Felucca;
|
|
var rect = new Rectangle2D(500, 500, Map.SectorSize * 2, Map.SectorSize * 2);
|
|
|
|
var clients = new[]
|
|
{
|
|
CreateClientWithMobile(map, new Point3D(rect.X + 1, rect.Y + 1, 0)),
|
|
CreateClientWithMobile(map, new Point3D(rect.X + Map.SectorSize + 1, rect.Y + 1, 0)),
|
|
CreateClientWithMobile(map, new Point3D(rect.X + Map.SectorSize + 1, rect.Y + Map.SectorSize + 1, 0))
|
|
};
|
|
|
|
try
|
|
{
|
|
var result = new List<NetState>();
|
|
foreach (var ns in map.GetClientsInBounds(rect))
|
|
{
|
|
result.Add(ns);
|
|
}
|
|
|
|
Assert.Equal(new[] { clients[0].Item1, clients[1].Item1, clients[2].Item1 }, result);
|
|
}
|
|
finally
|
|
{
|
|
DeleteAll(clients);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void ClientEnumerator_MapBoundsAreClamped()
|
|
{
|
|
var map = Map.Felucca;
|
|
var width = map.Width;
|
|
var height = map.Height;
|
|
|
|
var rect = new Rectangle2D(width - Map.SectorSize - 2, height - Map.SectorSize - 2, Map.SectorSize * 2, Map.SectorSize * 2);
|
|
|
|
var clients = new[]
|
|
{
|
|
CreateClientWithMobile(map, new Point3D(width - 2, height - 2, 0))
|
|
};
|
|
|
|
try
|
|
{
|
|
var enumerator = map.GetClientsInBounds(rect).GetEnumerator();
|
|
|
|
Assert.True(enumerator.MoveNext());
|
|
Assert.Equal(clients[0].Item1, enumerator.Current);
|
|
Assert.False(enumerator.MoveNext());
|
|
}
|
|
finally
|
|
{
|
|
DeleteAll(clients);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void ClientAtEnumerator_FiltersExactLocation()
|
|
{
|
|
var map = Map.Felucca;
|
|
var location = new Point3D(600, 600, 0);
|
|
var differentLocation = new Point3D(601, 600, 0);
|
|
|
|
var clients = new (NetState, Mobile)[3];
|
|
try
|
|
{
|
|
clients[0] = CreateClientWithMobile(map, location);
|
|
clients[1] = CreateClientWithMobile(map, location);
|
|
clients[2] = CreateClientWithMobile(map, differentLocation);
|
|
|
|
var found = new List<NetState>();
|
|
foreach (var ns in map.GetClientsAt(location))
|
|
{
|
|
found.Add(ns);
|
|
}
|
|
|
|
Assert.Equal(2, found.Count);
|
|
Assert.All(found, ns =>
|
|
{
|
|
Assert.NotNull(ns.Mobile);
|
|
Assert.Equal(location.X, ns.Mobile.X);
|
|
Assert.Equal(location.Y, ns.Mobile.Y);
|
|
});
|
|
Assert.Contains(clients[0].Item1, found);
|
|
Assert.Contains(clients[1].Item1, found);
|
|
}
|
|
finally
|
|
{
|
|
DeleteAll(clients);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void ClientAtEnumerator_SkipsNullMobiles()
|
|
{
|
|
var map = Map.Felucca;
|
|
var location = new Point3D(650, 650, 0);
|
|
|
|
var clients = new (NetState, Mobile)[3];
|
|
try
|
|
{
|
|
clients[0] = CreateClientWithMobile(map, location);
|
|
clients[1] = CreateClientWithMobile(map, location);
|
|
clients[2] = CreateClientWithMobile(map, location);
|
|
|
|
// Remove the mobile from the second client
|
|
clients[1].Item2.Delete();
|
|
clients[1].Item1.Mobile = null;
|
|
|
|
var found = new List<NetState>();
|
|
foreach (var ns in map.GetClientsAt(location))
|
|
{
|
|
found.Add(ns);
|
|
}
|
|
|
|
Assert.Equal(2, found.Count);
|
|
Assert.Equal(new[] { clients[0].Item1, clients[2].Item1 }, found);
|
|
}
|
|
finally
|
|
{
|
|
DeleteAll(clients);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void ClientAtEnumerator_MapNullYieldsEmpty()
|
|
{
|
|
var enumerator = new Map.ClientAtEnumerable(null, new Point2D(0, 0)).GetEnumerator();
|
|
Assert.False(enumerator.MoveNext());
|
|
}
|
|
|
|
[Fact]
|
|
public void ClientAtEnumerator_ThrowsOnVersionChange()
|
|
{
|
|
var map = Map.Felucca;
|
|
var location = new Point3D(750, 750, 0);
|
|
|
|
var clients = new[]
|
|
{
|
|
CreateClientWithMobile(map, location),
|
|
CreateClientWithMobile(map, location)
|
|
};
|
|
|
|
try
|
|
{
|
|
var enumerator = map.GetClientsAt(location).GetEnumerator();
|
|
Assert.True(enumerator.MoveNext());
|
|
|
|
clients[1].Item2.Delete();
|
|
|
|
// Ref structs cannot be captured in lambdas, so we test the exception directly
|
|
var exceptionThrown = false;
|
|
try
|
|
{
|
|
enumerator.MoveNext();
|
|
}
|
|
catch (InvalidOperationException)
|
|
{
|
|
exceptionThrown = true;
|
|
}
|
|
|
|
Assert.True(exceptionThrown, "Expected InvalidOperationException when collection version changes");
|
|
}
|
|
finally
|
|
{
|
|
DeleteAll(clients);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void ClientEnumerator_GetClientsInRange()
|
|
{
|
|
var map = Map.Felucca;
|
|
var center = new Point3D(900, 900, 0);
|
|
const int range = 5;
|
|
|
|
var clients = new (NetState, Mobile)[3];
|
|
try
|
|
{
|
|
clients[0] = CreateClientWithMobile(map, new Point3D(902, 902, 0)); // Within range
|
|
clients[1] = CreateClientWithMobile(map, new Point3D(898, 898, 0)); // Within range
|
|
clients[2] = CreateClientWithMobile(map, new Point3D(910, 910, 0)); // Outside range (906+ is outside)
|
|
|
|
var found = new List<NetState>();
|
|
foreach (var ns in map.GetClientsInRange(center, range))
|
|
{
|
|
found.Add(ns);
|
|
}
|
|
|
|
// GetClientsInRange uses a bounding rectangle, not circular distance
|
|
// Range of 5 means rectangle from (895, 895) to (905, 905)
|
|
Assert.Equal(2, found.Count);
|
|
Assert.Contains(clients[0].Item1, found);
|
|
Assert.Contains(clients[1].Item1, found);
|
|
}
|
|
finally
|
|
{
|
|
DeleteAll(clients);
|
|
}
|
|
}
|
|
|
|
private static (NetState, Mobile) CreateClientWithMobile(Map map, Point3D location)
|
|
{
|
|
// Create test NetState with real socket and buffers
|
|
var ns = PacketTestUtilities.CreateTestNetState();
|
|
|
|
// Assign a mock account to avoid null reference issues
|
|
ns.Account = new MockAccount();
|
|
|
|
// Use a unique serial for each mobile
|
|
var serial = World.NewMobile;
|
|
var mobile = new Mobile(serial);
|
|
mobile.DefaultMobileInit();
|
|
|
|
// Set the NetState on the mobile BEFORE moving it to the world
|
|
// so the sector's client list gets updated properly
|
|
ns.Mobile = mobile;
|
|
mobile.NetState = ns;
|
|
|
|
mobile.MoveToWorld(location, map);
|
|
return (ns, mobile);
|
|
}
|
|
|
|
[Fact]
|
|
public void ClientEnumerator_ZeroRangeReturnsOnlyCenter()
|
|
{
|
|
var map = Map.Felucca;
|
|
var center = new Point3D(950, 950, 0);
|
|
const int range = 0;
|
|
|
|
var clients = new (NetState, Mobile)[2];
|
|
try
|
|
{
|
|
clients[0] = CreateClientWithMobile(map, center); // Exact center
|
|
clients[1] = CreateClientWithMobile(map, new Point3D(951, 950, 0)); // 1 tile away
|
|
|
|
var found = new List<NetState>();
|
|
foreach (var ns in map.GetClientsInRange(center, range))
|
|
{
|
|
found.Add(ns);
|
|
}
|
|
|
|
Assert.Single(found);
|
|
Assert.Equal(clients[0].Item1, found[0]);
|
|
}
|
|
finally
|
|
{
|
|
DeleteAll(clients);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void ClientEnumerator_NegativeRangeCreates1x1Bounds()
|
|
{
|
|
var map = Map.Felucca;
|
|
var center = new Point3D(1050, 1050, 0);
|
|
const int range = -5;
|
|
|
|
var clients = new (NetState, Mobile)[2];
|
|
try
|
|
{
|
|
clients[0] = CreateClientWithMobile(map, center);
|
|
clients[1] = CreateClientWithMobile(map, new Point3D(1051, 1050, 0)); // 1 tile away
|
|
|
|
var found = new List<NetState>();
|
|
foreach (var ns in map.GetClientsInRange(center, range))
|
|
{
|
|
found.Add(ns);
|
|
}
|
|
|
|
// With negative range creating a 1x1 bounds, only exact center matches
|
|
Assert.Single(found);
|
|
Assert.Equal(clients[0].Item1, found[0]);
|
|
}
|
|
finally
|
|
{
|
|
DeleteAll(clients);
|
|
}
|
|
}
|
|
|
|
private static void DeleteAll((NetState state, Mobile m)[] clients)
|
|
{
|
|
for (var i = 0; i < clients.Length; i++)
|
|
{
|
|
if (clients[i].state != null)
|
|
{
|
|
clients[i].state.Mobile = null;
|
|
clients[i].state.Dispose();
|
|
}
|
|
clients[i].m?.Delete();
|
|
}
|
|
}
|
|
}
|
|
|