test: run tile-dependent tests on synthetic terrain instead of client files (#2725)
## Summary About 114 tests skipped on CI because they needed the official client files (`tiledata.mul`, map and multi files). They gave CI no signal, and locally they ran against whichever client a developer had installed. The test hosts now build their own world instead, so every test runs on CI and runs the same on every machine. CI simulation: Server.Tests 837 passed, UOContent.Tests 1131 passed, **0 skipped**. - **Generated tile data.** The fixtures write a pre-HS `tiledata.mul` from a small invented tile kit (`Server.Tests/Terrain/TestTiles`) and load it through the real `TileData.Load()`. The test hosts no longer read any client directory (`MODERNUO_CLIENT_PATH`, `MODERNUO_TEST_DATA_DIR` and `C:\Ultima Online Classic` are gone from test code). The file is written to `SyntheticData` in each test project's output, overwritten every run and removed by `dotnet clean`. - **Injected terrain.** `TestTerrain` stamps land and statics into Felucca and Trammel, which share one terrain. Writes after startup must go in a `TestTerrain.Scope()`, which puts back every block it touched and keeps the step cache fresh. - **Prefab scenes.** Seven named scenes (town, causeway, sewer walkway, coastline, deep sea, map-edge sea, an upstairs room with an L-shaped counter) replace the Britain coordinates the pathing, AI and fishing tests relied on. Each scene-based test asserts its scene is present first, so a missing scene fails instead of passing on flat ground. Stamping all seven takes 3-5 ms. - **Multi footprints.** Contrived footprints for the three multi IDs content looks up (0x74, 0x7A, 0x0) are seeded through a new internal `MultiData.SetComponents`. - **Fingerprint.** `StepCacheFile.HashTileDataFile` is extracted so a test can show that a one-flag change to the file changes the fingerprint, while runtime table mutation does not. ### Engine changes - `TileMatrix.GetLandBlock`/`GetStaticBlock`: on a map without its files, return the block injected with `SetLandBlock`/`SetStaticBlock`, or the default when nothing was injected. Maps with files take the same path as before. - `MultiData.SetComponents` (internal): registers a footprint without multi files. ### Test changes worth a look - Values that were properties of real Britain terrain (probes at Z 10, a pinned plain walk mask of 0xC1) are re-pinned to the synthetic plain (Z 0, 0xFF). - No tests were deleted. The multi walkability and boat-deck tests assert movement behaviour over a footprint, not what a real multi looks like, so they run on the contrived footprints. - Maps 0 and 1 keep file indexes 0 and 1, and every stamp writes both, rather than sharing one file index. On a map without files the getters never consult the shared-file cache, and its patch bits would hide one facet's injection from the other. ## Test plan - [x] `dotnet test -p:SolutionDir=... --filter "Category!=Manual"` with the client env vars pointed at an empty directory: 837 + 1131 passed, 0 skipped, 0 failed - [x] Mutation check: removing the step-cache clear from `TestTerrain` makes the stale-cache tests fail - [x] CI green on all platforms
This commit is contained in:
parent
00134cac33
commit
54c0040ac8
51 changed files with 1517 additions and 601 deletions
|
|
@ -33,7 +33,7 @@ public class StepCacheLifecycleTests : IDisposable
|
|||
/// <summary>Builds the plain chunk and hands it back for a test to inject state into.</summary>
|
||||
private static StepChunk BuiltPlainChunk(StepCache cache, Map map)
|
||||
{
|
||||
cache.TryGetMask(map, PlainX, PlainY, sourceZ: 10);
|
||||
cache.TryGetMask(map, PlainX, PlainY, sourceZ: PlainZ);
|
||||
|
||||
var chunk = cache.GetResidentChunk(map.MapID, PlainX >> 4, PlainY >> 4);
|
||||
Assert.NotNull(chunk);
|
||||
|
|
@ -53,7 +53,7 @@ public class StepCacheLifecycleTests : IDisposable
|
|||
var cache = FreshCache(promotionThreshold: 2);
|
||||
var map = TestMap;
|
||||
|
||||
var lookup = cache.TryGetMask(map, PlainX, PlainY, sourceZ: 10);
|
||||
var lookup = cache.TryGetMask(map, PlainX, PlainY, sourceZ: PlainZ);
|
||||
|
||||
Assert.False(lookup.IsHit);
|
||||
Assert.Equal(CacheHitKind.Fallthrough_NotBuilt, lookup.HitKind);
|
||||
|
|
@ -65,21 +65,19 @@ public class StepCacheLifecycleTests : IDisposable
|
|||
Assert.Equal(1L, stats.FallthroughNotBuilt);
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
[Fact]
|
||||
public void SecondTouchInsideWindow_PromotesAndServes()
|
||||
{
|
||||
TileDataRequirement.SkipIfMissing();
|
||||
|
||||
var cache = FreshCache(promotionThreshold: 2);
|
||||
var map = TestMap;
|
||||
|
||||
Assert.False(cache.TryGetMask(map, PlainX, PlainY, sourceZ: 10).IsHit);
|
||||
Assert.False(cache.TryGetMask(map, PlainX, PlainY, sourceZ: PlainZ).IsHit);
|
||||
|
||||
var promoted = cache.TryGetMask(map, PlainX, PlainY, sourceZ: 10);
|
||||
var promoted = cache.TryGetMask(map, PlainX, PlainY, sourceZ: PlainZ);
|
||||
Assert.True(promoted.IsHit);
|
||||
Assert.Equal(CacheHitKind.Miss_NotBuilt, promoted.HitKind);
|
||||
Assert.Equal((byte)0xC1, promoted.WalkMask); // pinned: open plain, walkable N/NE/... per the bake
|
||||
Assert.Equal((sbyte)10, promoted.WalkZ_N);
|
||||
Assert.Equal((byte)0xFF, promoted.WalkMask); // flat default ground: walkable in all eight directions
|
||||
Assert.Equal(PlainZ, promoted.WalkZ_N);
|
||||
|
||||
var stats = cache.GetStats();
|
||||
Assert.Equal(1, stats.ResidentChunks);
|
||||
|
|
@ -88,9 +86,9 @@ public class StepCacheLifecycleTests : IDisposable
|
|||
Assert.Equal(1L, stats.FallthroughNotBuilt);
|
||||
|
||||
// Now resident: a third query is a clean hit, not another miss.
|
||||
var hit = cache.TryGetMask(map, PlainX, PlainY, sourceZ: 10);
|
||||
var hit = cache.TryGetMask(map, PlainX, PlainY, sourceZ: PlainZ);
|
||||
Assert.Equal(CacheHitKind.Hit, hit.HitKind);
|
||||
Assert.Equal((byte)0xC1, hit.WalkMask);
|
||||
Assert.Equal((byte)0xFF, hit.WalkMask);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -106,10 +104,10 @@ public class StepCacheLifecycleTests : IDisposable
|
|||
|
||||
var map = TestMap;
|
||||
|
||||
Assert.False(cache.TryGetMask(map, PlainX, PlainY, sourceZ: 10).IsHit);
|
||||
Assert.False(cache.TryGetMask(map, PlainX, PlainY, sourceZ: PlainZ).IsHit);
|
||||
Thread.Sleep(20); // outrun the window
|
||||
|
||||
var second = cache.TryGetMask(map, PlainX, PlainY, sourceZ: 10);
|
||||
var second = cache.TryGetMask(map, PlainX, PlainY, sourceZ: PlainZ);
|
||||
Assert.False(second.IsHit);
|
||||
Assert.Equal(CacheHitKind.Fallthrough_NotBuilt, second.HitKind);
|
||||
Assert.Equal(0, cache.GetStats().ResidentChunks);
|
||||
|
|
@ -121,11 +119,9 @@ public class StepCacheLifecycleTests : IDisposable
|
|||
/// there, so counting probes would cross any threshold on the second cell and gate nothing at
|
||||
/// all — the deferral would be dead code.
|
||||
/// </summary>
|
||||
[SkippableFact]
|
||||
[Fact]
|
||||
public void ManyProbesInOneFind_CountAsOneTouch()
|
||||
{
|
||||
TileDataRequirement.SkipIfMissing();
|
||||
|
||||
var cache = FreshCache(promotionThreshold: 2);
|
||||
var map = TestMap;
|
||||
|
||||
|
|
@ -133,7 +129,7 @@ public class StepCacheLifecycleTests : IDisposable
|
|||
for (var i = 0; i < 8; i++)
|
||||
{
|
||||
// Eight different cells, all inside the same chunk.
|
||||
var lookup = cache.TryGetMask(map, PlainX + i, PlainY, sourceZ: 10);
|
||||
var lookup = cache.TryGetMask(map, PlainX + i, PlainY, sourceZ: PlainZ);
|
||||
Assert.False(lookup.IsHit);
|
||||
Assert.Equal(CacheHitKind.Fallthrough_NotBuilt, lookup.HitKind);
|
||||
}
|
||||
|
|
@ -144,7 +140,7 @@ public class StepCacheLifecycleTests : IDisposable
|
|||
|
||||
// A second Find is the second distinct touch, and crosses the threshold.
|
||||
cache.BeginFindGeneration();
|
||||
var promoted = cache.TryGetMask(map, PlainX, PlainY, sourceZ: 10);
|
||||
var promoted = cache.TryGetMask(map, PlainX, PlainY, sourceZ: PlainZ);
|
||||
|
||||
Assert.Equal(CacheHitKind.Miss_NotBuilt, promoted.HitKind);
|
||||
Assert.Equal(1, cache.GetStats().ResidentChunks);
|
||||
|
|
@ -161,12 +157,12 @@ public class StepCacheLifecycleTests : IDisposable
|
|||
var map = TestMap;
|
||||
|
||||
cache.BeginFindGeneration();
|
||||
Assert.False(cache.TryGetMask(map, PlainX, PlainY, sourceZ: 10).IsHit);
|
||||
Assert.False(cache.TryGetMask(map, PlainX, PlainY, sourceZ: PlainZ).IsHit);
|
||||
|
||||
Thread.Sleep(20);
|
||||
|
||||
cache.BeginFindGeneration();
|
||||
var second = cache.TryGetMask(map, PlainX, PlainY, sourceZ: 10);
|
||||
var second = cache.TryGetMask(map, PlainX, PlainY, sourceZ: PlainZ);
|
||||
|
||||
Assert.Equal(CacheHitKind.Fallthrough_NotBuilt, second.HitKind);
|
||||
Assert.Equal(0, cache.GetStats().ResidentChunks);
|
||||
|
|
@ -179,8 +175,8 @@ public class StepCacheLifecycleTests : IDisposable
|
|||
var map = TestMap;
|
||||
|
||||
// One touch each, in two different chunks: neither reaches the threshold on its own.
|
||||
Assert.False(cache.TryGetMask(map, PlainX, PlainY, sourceZ: 10).IsHit);
|
||||
Assert.False(cache.TryGetMask(map, 1600, 1700, sourceZ: 10).IsHit);
|
||||
Assert.False(cache.TryGetMask(map, PlainX, PlainY, sourceZ: PlainZ).IsHit);
|
||||
Assert.False(cache.TryGetMask(map, 1600, 1700, sourceZ: PlainZ).IsHit);
|
||||
|
||||
Assert.Equal(0, cache.GetStats().ResidentChunks);
|
||||
Assert.Equal(2L, cache.GetStats().FallthroughNotBuilt);
|
||||
|
|
@ -202,16 +198,14 @@ public class StepCacheLifecycleTests : IDisposable
|
|||
/// A multi's cells fall through, and so does the 1-cell halo around it: a cell's mask encodes
|
||||
/// the edges TO its neighbours, so a wall one cell over has to block them.
|
||||
/// </summary>
|
||||
[SkippableFact]
|
||||
[Fact]
|
||||
public void MultiCoveredCell_AndItsHalo_FallThrough()
|
||||
{
|
||||
TileDataRequirement.SkipIfMissing();
|
||||
|
||||
var cache = FreshCache(promotionThreshold: 1);
|
||||
var map = TestMap;
|
||||
|
||||
// A cell nowhere near a multi still serves from the static cache.
|
||||
Assert.True(cache.TryGetMask(map, PlainX, PlainY, 10).IsHit);
|
||||
Assert.True(cache.TryGetMask(map, PlainX, PlainY, PlainZ).IsHit);
|
||||
|
||||
// Mark an isolated sector as multi-bearing. Sector.HasMultis only tests Count > 0 and the
|
||||
// fallthrough never dereferences the multi, so a single null entry is enough — no real
|
||||
|
|
@ -254,7 +248,7 @@ public class StepCacheLifecycleTests : IDisposable
|
|||
var cache = FreshCache(promotionThreshold: 1);
|
||||
var map = TestMap;
|
||||
|
||||
cache.TryGetMask(map, PlainX, PlainY, sourceZ: 10);
|
||||
cache.TryGetMask(map, PlainX, PlainY, sourceZ: PlainZ);
|
||||
var before = cache.GetStats().FallthroughSourceZMismatch;
|
||||
|
||||
var lookup = cache.TryGetMask(map, PlainX, PlainY, sourceZ: 100);
|
||||
|
|
@ -296,8 +290,8 @@ public class StepCacheLifecycleTests : IDisposable
|
|||
offsets[CellIndex(PlainX, PlainY)] = 0;
|
||||
chunk.SetStrata(offsets, OneStratum(zCenter: 42));
|
||||
|
||||
// 10 is more than StepHeight from the only stratum, so nothing can answer.
|
||||
var lookup = cache.TryGetMask(map, PlainX, PlainY, sourceZ: 10);
|
||||
// The plain is more than StepHeight below the only stratum (Z 42), so nothing can answer.
|
||||
var lookup = cache.TryGetMask(map, PlainX, PlainY, sourceZ: PlainZ);
|
||||
|
||||
Assert.False(lookup.IsHit);
|
||||
Assert.Equal(CacheHitKind.Fallthrough_MultiZ, lookup.HitKind);
|
||||
|
|
@ -321,7 +315,7 @@ public class StepCacheLifecycleTests : IDisposable
|
|||
offsets[CellIndex(PlainX, PlainY)] = 0;
|
||||
chunk.SetStrata(offsets, [0]); // a record declaring zero strata
|
||||
|
||||
var lookup = cache.TryGetMask(map, PlainX, PlainY, sourceZ: 10);
|
||||
var lookup = cache.TryGetMask(map, PlainX, PlainY, sourceZ: PlainZ);
|
||||
|
||||
Assert.False(lookup.IsHit);
|
||||
Assert.Equal(CacheHitKind.Fallthrough_MultiZ, lookup.HitKind);
|
||||
|
|
@ -400,7 +394,7 @@ public class StepCacheLifecycleTests : IDisposable
|
|||
// the count comes down and the key list stays in step, so equal touch ticks are fine.
|
||||
for (var i = 0; i < 5; i++)
|
||||
{
|
||||
cache.TryGetMask(map, PlainX + i * 16, PlainY, sourceZ: 10);
|
||||
cache.TryGetMask(map, PlainX + i * 16, PlainY, sourceZ: PlainZ);
|
||||
}
|
||||
|
||||
cache.EnforceLruCap();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue