The first commit converted the four members the issue named and left the other sites alone, reasoning that none had been observed failing. A 20-run complete-solution baseline disproved that within minutes: run 2 LiveEntityRuntimeTests.AnimationView_HotSpatialTraversal… run 14 StaticRenderProjectionJournalTests.ActiveAnimatedSynchronization… run 18 StaticRenderProjectionJournalTests.ActiveAnimatedSynchronization… run 19 CurrentRenderSceneOracleTests.SurfaceOverrideFingerprint… Both new names are the same shape as the four — one warm call, then a thousand-iteration loop inside the measured window — and neither had been recorded anywhere. "Not observed failing" only ever meant "not yet observed", and leaving known-shape sites in place would have guaranteed the acceptance gate failed. Run 19 is the sharper lesson: the issue named `SurfaceOverrideFingerprint_DictionaryHotPathAllocatesNothing`, and the first commit converted a *different* test in that same file, so the actually-named member was still on the old shape. Matching by file was not matching by test. Every strict-zero site in the assembly is now on the probe — ten tests. Two came out stricter rather than merely steadier: `StaticRenderProjectionJournalTests` was measuring a synchronise whose journal does **not** coalesce. Repeating it grew the journal by 1,000 entries per call — 192,000 by the end of a probe run — so the steady state the test claimed to measure did not exist and the single-call window had been hiding it. Its step is now the whole frame cycle, synchronise *and* drain, which puts `DrainTo` inside the measured window for the first time and asserts the journal ends empty. `RetailInboundEventDispatcherTests` asserted a hard-coded 1,001 callbacks. It now counts its own dispatches and pins the callback count against that, so the assertion still proves the fast path ran the callback every time without being coupled to a loop bound that no longer exists. Left alone deliberately: the four sites asserting a tolerance rather than zero — `CellViewDedupTests` and `PortalProjectionTests`. Their ceilings already absorb this noise and none has flaked; changing a bound in either direction is a separate decision from fixing a measurement. Worth noting that `PortalProjectionTests`' ceiling exists explicitly to tolerate "a tiered-JIT/ArrayPool bookkeeping transition ... to the first measured batch", which is exactly what the probe removes, so it could probably be tightened to zero now — recorded in the issue rather than done here. Solution build 0 warnings / 0 errors; App suite 3,941 passed / 3 skipped. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
117 lines
3.5 KiB
C#
117 lines
3.5 KiB
C#
using AcDream.App.World;
|
|
|
|
namespace AcDream.App.Tests.World;
|
|
|
|
public sealed class RetailInboundEventDispatcherTests
|
|
{
|
|
private sealed class Counter
|
|
{
|
|
public int Value;
|
|
}
|
|
|
|
[Fact]
|
|
public void NestedEvents_DrainAfterCompleteOuterTail_InArrivalOrder()
|
|
{
|
|
var dispatcher = new RetailInboundEventDispatcher();
|
|
var calls = new List<string>();
|
|
|
|
dispatcher.Run(() =>
|
|
{
|
|
calls.Add("position-head");
|
|
dispatcher.Run(() => calls.Add("state"));
|
|
dispatcher.Run(() => calls.Add("vector"));
|
|
calls.Add("position-tail");
|
|
});
|
|
|
|
Assert.Equal(
|
|
["position-head", "position-tail", "state", "vector"],
|
|
calls);
|
|
Assert.False(dispatcher.IsDraining);
|
|
Assert.Equal(0, dispatcher.PendingCount);
|
|
}
|
|
|
|
[Fact]
|
|
public void FrameOperation_DefersInboundMutationUntilQuantumTail()
|
|
{
|
|
var dispatcher = new RetailInboundEventDispatcher();
|
|
var calls = new List<string>();
|
|
|
|
dispatcher.Run(() =>
|
|
{
|
|
calls.Add("physics");
|
|
dispatcher.Run(() => calls.Add("position"));
|
|
calls.Add("shadow-and-hooks");
|
|
});
|
|
|
|
Assert.Equal(["physics", "shadow-and-hooks", "position"], calls);
|
|
}
|
|
|
|
[Fact]
|
|
public void NestedStateOperations_DrainAfterOuterTail_InArrivalOrder()
|
|
{
|
|
var dispatcher = new RetailInboundEventDispatcher();
|
|
var calls = new List<string>();
|
|
|
|
dispatcher.Run(
|
|
dispatcher,
|
|
calls,
|
|
static (active, output) =>
|
|
{
|
|
output.Add("position-head");
|
|
active.Run(
|
|
output,
|
|
"state",
|
|
static (target, value) => target.Add(value));
|
|
output.Add("position-tail");
|
|
});
|
|
|
|
Assert.Equal(["position-head", "position-tail", "state"], calls);
|
|
Assert.False(dispatcher.IsDraining);
|
|
Assert.Equal(0, dispatcher.PendingCount);
|
|
}
|
|
|
|
[Fact]
|
|
public void Failure_DiscardsQueuedTailAndLeavesDispatcherReusable()
|
|
{
|
|
var dispatcher = new RetailInboundEventDispatcher();
|
|
bool queuedRan = false;
|
|
|
|
Assert.Throws<InvalidOperationException>(() => dispatcher.Run(() =>
|
|
{
|
|
dispatcher.Run(() => queuedRan = true);
|
|
throw new InvalidOperationException("packet failed");
|
|
}));
|
|
|
|
Assert.False(queuedRan);
|
|
Assert.False(dispatcher.IsDraining);
|
|
Assert.Equal(0, dispatcher.PendingCount);
|
|
|
|
dispatcher.Run(() => queuedRan = true);
|
|
Assert.True(queuedRan);
|
|
}
|
|
|
|
[Fact]
|
|
public void StateFastPath_DoesNotAllocateAfterWarmup()
|
|
{
|
|
var dispatcher = new RetailInboundEventDispatcher();
|
|
var counter = new Counter();
|
|
Action<Counter, int> increment =
|
|
static (target, amount) => target.Value += amount;
|
|
dispatcher.Run(counter, 1, increment);
|
|
|
|
// #250: the measured window was a 1,000-iteration loop written inline.
|
|
int dispatches = 0;
|
|
ZeroAllocationProbe.AssertAllocatesNothing(
|
|
"RetailInboundEventDispatcher.Run state fast path",
|
|
() =>
|
|
{
|
|
dispatches++;
|
|
dispatcher.Run(counter, 1, increment);
|
|
});
|
|
|
|
// The fast path really ran the callback on every dispatch — once for
|
|
// the priming call above, then once per probe invocation.
|
|
Assert.True(dispatches > 0);
|
|
Assert.Equal(dispatches + 1, counter.Value);
|
|
}
|
|
}
|