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:
Kamron Batman 2026-10-18 20:11:33 -07:00 • committed by GitHub
parent 79f736aa83
commit 00134cac33
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
135 changed files with 3164 additions and 4020 deletions

View file

@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using Xunit;
namespace Server.Tests;
@ -107,83 +105,48 @@ public class AnchoredTimePersistenceTests
[Fact]
public void SaveStartAnchor_RebasesAnchoredTimestampsAtLoad()
{
var previousAssemblies = AssemblyHandler.Assemblies;
AssemblyHandler.Assemblies = [.. previousAssemblies ?? [], typeof(AnchoredEntity).Assembly];
// The scope also restores World.SaveStartTime, which this test backdates.
using var pipeline = new PersistencePipelineScope(
2,
installWorkers: true,
visibleAssembly: typeof(AnchoredEntity).Assembly,
directoryPrefix: "muo-anchored"
);
var source = pipeline.Source;
var dir = pipeline.Directory;
var source = new SerializationChunkSource();
var workers = new SerializationThreadWorker[2];
for (var i = 0; i < workers.Length; i++)
{
workers[i] = new SerializationThreadWorker(i, source);
workers[i].AllocateHeap();
}
var persistence = pipeline.Track(new AnchoredPersistence(2100));
var previousWorkers = World._threadWorkers;
World._threadWorkers = workers;
var lastRested = Core.Now - TimeSpan.FromMinutes(10);
var serial = (Serial)1u;
persistence.EntitiesBySerial[serial] = new AnchoredEntity(serial) { LastRested = lastRested };
persistence.RegisterType(typeof(AnchoredEntity));
var previousSaveStart = World.SaveStartTime;
// Pretend the save started two hours ago, as if the server had been down since.
var downtime = TimeSpan.FromHours(2);
World.SaveStartTime = Core.Now - downtime;
var persistence = new AnchoredPersistence(2100);
AnchoredPersistence loaded = null;
pipeline.WakeWorkers();
var dir = Path.Combine(Path.GetTempPath(), $"muo-anchored-{Guid.NewGuid():N}");
Directory.CreateDirectory(dir);
source.SetOwner(persistence);
Assert.True(persistence.TrySnapshotEntries(out var slotCount));
source.PushSlotRanges(persistence, slotCount);
try
{
var lastRested = Core.Now - TimeSpan.FromMinutes(10);
var serial = (Serial)1u;
persistence.EntitiesBySerial[serial] = new AnchoredEntity(serial) { LastRested = lastRested };
persistence.RegisterType(typeof(AnchoredEntity));
pipeline.FlushAndSleepWorkers();
// Pretend the save started two hours ago, as if the server had been down since.
var downtime = TimeSpan.FromHours(2);
World.SaveStartTime = Core.Now - downtime;
persistence.WriteSnapshot(dir);
persistence.PostWorldSave();
foreach (var worker in workers)
{
worker.Wake();
}
var loaded = pipeline.Track(new AnchoredPersistence(2101));
loaded.DeserializeIndexes(dir, null);
loaded.Deserialize(dir, null);
source.SetOwner(persistence);
Assert.True(persistence.TrySnapshotEntries(out var slotCount));
source.PushSlotRanges(persistence, slotCount);
var entity = loaded.EntitiesBySerial[serial];
var expected = lastRested + downtime;
source.Flush();
foreach (var worker in workers)
{
worker.Sleep();
}
persistence.WriteSnapshot(dir);
persistence.PostWorldSave();
loaded = new AnchoredPersistence(2101);
loaded.DeserializeIndexes(dir, null);
loaded.Deserialize(dir, null);
var entity = loaded.EntitiesBySerial[serial];
var expected = lastRested + downtime;
Assert.True(
(entity.LastRested - expected).Duration() <= TimeSpan.FromSeconds(30),
$"Anchored timestamp must re-base by the downtime; expected ~{expected}, got {entity.LastRested}."
);
}
finally
{
World.SaveStartTime = previousSaveStart;
persistence.Unregister();
loaded?.Unregister();
foreach (var worker in workers)
{
worker.Exit();
}
World._threadWorkers = previousWorkers;
AssemblyHandler.Assemblies = previousAssemblies;
Directory.Delete(dir, true);
}
Assert.True(
(entity.LastRested - expected).Duration() <= TimeSpan.FromSeconds(30),
$"Anchored timestamp must re-base by the downtime; expected ~{expected}, got {entity.LastRested}."
);
}
}

View file

@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using Xunit;
namespace Server.Tests;
@ -72,103 +70,68 @@ public class GenericEntityPersistenceRoundTripTests
[Fact]
public void SnapshotRoundTripsThroughWorkersAndSegmentLogs()
{
// The loader resolves types by hash through AssemblyHandler; make this test
// assembly visible for the duration of the test.
var previousAssemblies = AssemblyHandler.Assemblies;
AssemblyHandler.Assemblies = [.. previousAssemblies ?? [], typeof(RoundTripEntity).Assembly];
// The loader resolves types by hash through AssemblyHandler, so this test assembly must be visible.
using var pipeline = new PersistencePipelineScope(
3,
installWorkers: true,
visibleAssembly: typeof(RoundTripEntity).Assembly,
directoryPrefix: "muo-roundtrip"
);
var source = pipeline.Source;
var dir = pipeline.Directory;
var source = new SerializationChunkSource();
var workers = new SerializationThreadWorker[3];
for (var i = 0; i < workers.Length; i++)
var persistence = pipeline.Track(new RoundTripPersistence(2000));
const int entityCount = 25_000;
var rng = new System.Random(0x5EED);
for (var i = 1; i <= entityCount; i++)
{
workers[i] = new SerializationThreadWorker(i, source);
workers[i].AllocateHeap();
var serial = (Serial)(uint)i;
persistence.EntitiesBySerial[serial] = new RoundTripEntity(serial)
{
Value = rng.Next(),
Name = i % 5 == 0 ? null : $"entity-{i}"
};
}
var previousWorkers = World._threadWorkers;
World._threadWorkers = workers;
persistence.RegisterType(typeof(RoundTripEntity));
var persistence = new RoundTripPersistence(2000);
RoundTripPersistence loaded = null;
// Freeze: what Persistence.SerializeAll + GenericEntityPersistence.Serialize do,
// against this test's chunk source instead of the world's.
pipeline.WakeWorkers();
var dir = Path.Combine(Path.GetTempPath(), $"muo-roundtrip-{Guid.NewGuid():N}");
Directory.CreateDirectory(dir);
source.SetOwner(persistence);
source.PushSingle(persistence);
Assert.True(persistence.TrySnapshotEntries(out var slotCount));
source.PushSlotRanges(persistence, slotCount);
try
pipeline.FlushAndSleepWorkers();
// Background write phase: snapshot from the segment logs. v4 embeds the type
// table in the idx, so no SerializedTypes.db is produced or needed.
persistence.WriteSnapshot(dir);
persistence.PostWorldSave(); // releases the entries snapshot
// Load into a fresh persistence, like a server boot would.
var loaded = pipeline.Track(new RoundTripPersistence(2001));
loaded.DeserializeIndexes(dir, null);
loaded.Deserialize(dir, null);
Assert.True(loaded.SelfPayloadDeserialized);
Assert.Equal(persistence.EntitiesBySerial.Count, loaded.EntitiesBySerial.Count);
foreach (var (serial, original) in persistence.EntitiesBySerial)
{
const int entityCount = 25_000;
var rng = new System.Random(0x5EED);
for (var i = 1; i <= entityCount; i++)
{
var serial = (Serial)(uint)i;
persistence.EntitiesBySerial[serial] = new RoundTripEntity(serial)
{
Value = rng.Next(),
Name = i % 5 == 0 ? null : $"entity-{i}"
};
}
persistence.RegisterType(typeof(RoundTripEntity));
// Freeze: what Persistence.SerializeAll + GenericEntityPersistence.Serialize do,
// against this test's chunk source instead of the world's.
foreach (var worker in workers)
{
worker.Wake();
}
source.SetOwner(persistence);
source.PushSingle(persistence);
Assert.True(persistence.TrySnapshotEntries(out var slotCount));
source.PushSlotRanges(persistence, slotCount);
// Mirrors World.PauseSerializationThreads
source.Flush();
foreach (var worker in workers)
{
worker.Sleep();
}
// Background write phase: snapshot from the segment logs. v4 embeds the type
// table in the idx, so no SerializedTypes.db is produced or needed.
persistence.WriteSnapshot(dir);
persistence.PostWorldSave(); // releases the entries snapshot
// Load into a fresh persistence, like a server boot would.
loaded = new RoundTripPersistence(2001);
loaded.DeserializeIndexes(dir, null);
loaded.Deserialize(dir, null);
Assert.True(loaded.SelfPayloadDeserialized);
Assert.Equal(persistence.EntitiesBySerial.Count, loaded.EntitiesBySerial.Count);
foreach (var (serial, original) in persistence.EntitiesBySerial)
{
var entity = loaded.EntitiesBySerial[serial];
Assert.Equal(original.Value, entity.Value);
Assert.Equal(original.Name, entity.Name);
Assert.Equal(original.Created.Ticks, entity.Created.Ticks);
}
// Loading must hydrate the type table so the next save can write indexes.
Assert.True(loaded.TryGetTypeIndex(typeof(RoundTripEntity), out _));
var entity = loaded.EntitiesBySerial[serial];
Assert.Equal(original.Value, entity.Value);
Assert.Equal(original.Name, entity.Name);
Assert.Equal(original.Created.Ticks, entity.Created.Ticks);
}
finally
{
persistence.Unregister();
loaded?.Unregister();
foreach (var worker in workers)
{
worker.Exit();
}
World._threadWorkers = previousWorkers;
AssemblyHandler.Assemblies = previousAssemblies;
Directory.Delete(dir, true);
}
// Loading must hydrate the type table so the next save can write indexes.
Assert.True(loaded.TryGetTypeIndex(typeof(RoundTripEntity), out _));
}
/// <summary>
@ -179,70 +142,44 @@ public class GenericEntityPersistenceRoundTripTests
[Fact]
public void SerializerException_IsRecordedOnTheWorker_AndTheDrainCompletes()
{
var source = new SerializationChunkSource();
var workers = new SerializationThreadWorker[2];
for (var i = 0; i < workers.Length; i++)
using var pipeline = new PersistencePipelineScope(2);
var source = pipeline.Source;
var workers = pipeline.Workers;
var persistence = pipeline.Track(new RoundTripPersistence(2002));
for (var i = 1; i <= 100; i++)
{
workers[i] = new SerializationThreadWorker(i, source);
workers[i].AllocateHeap();
var serial = (Serial)(uint)i;
persistence.EntitiesBySerial[serial] = i == 50
? new ThrowingRoundTripEntity(serial)
: new RoundTripEntity(serial) { Value = i, Name = $"entity-{i}" };
}
var persistence = new RoundTripPersistence(2002);
pipeline.WakeWorkers();
try
source.SetOwner(persistence);
Assert.True(persistence.TrySnapshotEntries(out var slotCount));
source.PushSlotRanges(persistence, slotCount);
pipeline.FlushAndSleepWorkers();
Exception error = null;
foreach (var worker in workers)
{
for (var i = 1; i <= 100; i++)
{
var serial = (Serial)(uint)i;
persistence.EntitiesBySerial[serial] = i == 50
? new ThrowingRoundTripEntity(serial)
: new RoundTripEntity(serial) { Value = i, Name = $"entity-{i}" };
}
foreach (var worker in workers)
{
worker.Wake();
}
source.SetOwner(persistence);
Assert.True(persistence.TrySnapshotEntries(out var slotCount));
source.PushSlotRanges(persistence, slotCount);
source.Flush();
foreach (var worker in workers)
{
worker.Sleep();
}
Exception error = null;
foreach (var worker in workers)
{
error ??= worker.Error;
}
Assert.IsType<InvalidOperationException>(error);
persistence.PostWorldSave();
// The next drain starts clean.
foreach (var worker in workers)
{
worker.Wake();
}
foreach (var worker in workers)
{
worker.Sleep();
Assert.Null(worker.Error);
}
error ??= worker.Error;
}
finally
{
persistence.Unregister();
foreach (var worker in workers)
{
worker.Exit();
}
Assert.IsType<InvalidOperationException>(error);
persistence.PostWorldSave();
// The next drain starts clean.
pipeline.WakeWorkers();
foreach (var worker in workers)
{
worker.Sleep();
Assert.Null(worker.Error);
}
}
@ -253,60 +190,28 @@ public class GenericEntityPersistenceRoundTripTests
[Fact]
public void WriteSnapshot_FailsTheSave_InsteadOfDroppingASegment()
{
var source = new SerializationChunkSource();
var workers = new SerializationThreadWorker[2];
for (var i = 0; i < workers.Length; i++)
using var pipeline = new PersistencePipelineScope(2, installWorkers: true, directoryPrefix: "muo-segmentfail");
var source = pipeline.Source;
var persistence = pipeline.Track(new RoundTripPersistence(2003));
for (var i = 1; i <= 100; i++)
{
workers[i] = new SerializationThreadWorker(i, source);
workers[i].AllocateHeap();
var serial = (Serial)(uint)i;
persistence.EntitiesBySerial[serial] = new RoundTripEntity(serial) { Value = i, Name = $"entity-{i}" };
}
var previousWorkers = World._threadWorkers;
World._threadWorkers = workers;
// Deliberately not registered: the writer cannot index the type.
var persistence = new RoundTripPersistence(2003);
var dir = Path.Combine(Path.GetTempPath(), $"muo-segmentfail-{Guid.NewGuid():N}");
Directory.CreateDirectory(dir);
pipeline.WakeWorkers();
try
{
for (var i = 1; i <= 100; i++)
{
var serial = (Serial)(uint)i;
persistence.EntitiesBySerial[serial] = new RoundTripEntity(serial) { Value = i, Name = $"entity-{i}" };
}
source.SetOwner(persistence);
Assert.True(persistence.TrySnapshotEntries(out var slotCount));
source.PushSlotRanges(persistence, slotCount);
// Deliberately not registered: the writer cannot index the type.
pipeline.FlushAndSleepWorkers();
foreach (var worker in workers)
{
worker.Wake();
}
source.SetOwner(persistence);
Assert.True(persistence.TrySnapshotEntries(out var slotCount));
source.PushSlotRanges(persistence, slotCount);
source.Flush();
foreach (var worker in workers)
{
worker.Sleep();
}
Assert.Throws<InvalidOperationException>(() => persistence.WriteSnapshot(dir));
persistence.PostWorldSave();
}
finally
{
persistence.Unregister();
foreach (var worker in workers)
{
worker.Exit();
}
World._threadWorkers = previousWorkers;
Directory.Delete(dir, true);
}
Assert.Throws<InvalidOperationException>(() => persistence.WriteSnapshot(pipeline.Directory));
persistence.PostWorldSave();
}
}

View file

@ -199,114 +199,91 @@ public class SerializationChunkSourceTests
[Fact]
public void WorkersDrainAllEntitiesAndLogSegments()
{
var source = new SerializationChunkSource();
var owner = new TestPersistence { PayloadSize = 512 * 1024 };
var workers = new SerializationThreadWorker[2];
for (var i = 0; i < workers.Length; i++)
using var pipeline = new PersistencePipelineScope(2);
var source = pipeline.Source;
var workers = pipeline.Workers;
var owner = pipeline.Track(new TestPersistence { PayloadSize = 512 * 1024 });
var entities = new List<TestEntity>();
for (var i = 0; i < 10_000; i++)
{
workers[i] = new SerializationThreadWorker(i, source);
workers[i].AllocateHeap();
entities.Add(new TestEntity { PayloadSize = 16 + i % 64 });
}
try
pipeline.WakeWorkers();
// A large payload published as a dedicated single chunk (a persistence
// self-payload), interleaved with the bare entity stream.
source.SetOwner(owner);
for (var i = 0; i < entities.Count; i++)
{
var entities = new List<TestEntity>();
for (var i = 0; i < 10_000; i++)
if (i == 5000)
{
entities.Add(new TestEntity { PayloadSize = 16 + i % 64 });
source.PushSingle(owner);
}
foreach (var worker in workers)
{
worker.Wake();
}
source.Push(entities[i]);
}
// A large payload published as a dedicated single chunk (a persistence
// self-payload), interleaved with the bare entity stream.
source.SetOwner(owner);
for (var i = 0; i < entities.Count; i++)
pipeline.FlushAndSleepWorkers();
long totalEntities = 0;
long totalBytes = 0;
foreach (var worker in workers)
{
totalEntities += worker.EntitiesSerialized;
totalBytes += worker.BytesSerialized;
}
Assert.Equal(entities.Count + 1, totalEntities);
// The self-payload recorded its placement on the persistence itself.
var (selfThread, selfPosition, selfLength) = owner.Placement;
Assert.Equal(owner.PayloadSize, selfLength);
Assert.InRange(selfThread, (byte)0, (byte)(workers.Length - 1));
var selfHeap = workers[selfThread].GetHeap(selfPosition, selfLength);
Assert.Equal(0, selfHeap[0]);
Assert.Equal((selfLength - 1) & 0xFF, selfHeap[^1]);
// Every entity appears exactly once in the worker segment logs, with a
// consistent span on that worker's heap: positions are implicit (contiguous
// writes), identity comes from the buffer-entities log.
var seen = new HashSet<TestEntity>();
long expectedBytes = owner.PayloadSize;
foreach (var e in entities)
{
expectedBytes += e.PayloadSize;
}
foreach (var worker in workers)
{
var lengths = worker.Lengths;
var bufferEntities = worker.BufferEntities;
foreach (var segment in worker.Segments)
{
if (i == 5000)
Assert.Same(owner, segment.Owner);
Assert.Equal(-1, segment.SlotOffset);
var heapPos = (int)segment.HeapStart;
for (var i = 0; i < segment.RecordCount; i++)
{
source.PushSingle(owner);
}
var entity = (TestEntity)bufferEntities[segment.EntitiesStart + i];
var length = lengths[segment.LengthsStart + i];
source.Push(entities[i]);
}
Assert.True(seen.Add(entity));
Assert.Equal(entity.PayloadSize, length);
// Mirrors World.PauseSerializationThreads
source.Flush();
foreach (var worker in workers)
{
worker.Sleep();
}
var heap = workers[Array.IndexOf(workers, worker)].GetHeap(heapPos, length);
Assert.Equal(0, heap[0]);
Assert.Equal((length - 1) & 0xFF, heap[^1]);
long totalEntities = 0;
long totalBytes = 0;
foreach (var worker in workers)
{
totalEntities += worker.EntitiesSerialized;
totalBytes += worker.BytesSerialized;
}
Assert.Equal(entities.Count + 1, totalEntities);
// The self-payload recorded its placement on the persistence itself.
var (selfThread, selfPosition, selfLength) = owner.Placement;
Assert.Equal(owner.PayloadSize, selfLength);
Assert.InRange(selfThread, (byte)0, (byte)(workers.Length - 1));
var selfHeap = workers[selfThread].GetHeap(selfPosition, selfLength);
Assert.Equal(0, selfHeap[0]);
Assert.Equal((selfLength - 1) & 0xFF, selfHeap[^1]);
// Every entity appears exactly once in the worker segment logs, with a
// consistent span on that worker's heap: positions are implicit (contiguous
// writes), identity comes from the buffer-entities log.
var seen = new HashSet<TestEntity>();
long expectedBytes = owner.PayloadSize;
foreach (var e in entities)
{
expectedBytes += e.PayloadSize;
}
foreach (var worker in workers)
{
var lengths = worker.Lengths;
var bufferEntities = worker.BufferEntities;
foreach (var segment in worker.Segments)
{
Assert.Same(owner, segment.Owner);
Assert.Equal(-1, segment.SlotOffset);
var heapPos = (int)segment.HeapStart;
for (var i = 0; i < segment.RecordCount; i++)
{
var entity = (TestEntity)bufferEntities[segment.EntitiesStart + i];
var length = lengths[segment.LengthsStart + i];
Assert.True(seen.Add(entity));
Assert.Equal(entity.PayloadSize, length);
var heap = workers[Array.IndexOf(workers, worker)].GetHeap(heapPos, length);
Assert.Equal(0, heap[0]);
Assert.Equal((length - 1) & 0xFF, heap[^1]);
heapPos += length;
}
heapPos += length;
}
}
}
Assert.Equal(entities.Count, seen.Count);
Assert.Equal(expectedBytes, totalBytes);
}
finally
{
owner.Unregister();
foreach (var worker in workers)
{
worker.Exit();
}
}
Assert.Equal(entities.Count, seen.Count);
Assert.Equal(expectedBytes, totalBytes);
}
}