Files
Workspace/Tools/AgentSupport/RuntimeTests/EventBusAllocationTests.cs
T
cneicy 0bffb65ae9
Validate ShrinkSDK Workspace / catalog (push) Failing after 5s
Validate ShrinkSDK Workspace / unity (push) Skipped
chore: release EventBus 2.3.2 and verify standalone allocation behavior
2026-11-06 21:01:16 +08:00

31 lines
1.0 KiB
C#

using System;
using NUnit.Framework;
using ShrinkEventBus;
[TestFixture, NonParallelizable]
public class EventBusAllocationTests
{
private readonly struct ProbeEvent : IShrinkEvent { }
[Test]
public void PublicDiagnosticsDoesNotAllocatePerPostAfterWarmup()
{
using var host = new ShrinkEventBusHost();
var bus = host.CreateBus(new ShrinkBusKey("allocation", "probe"), ShrinkBusOptions.Inline());
var calls = 0;
using var observer = EventBus.ObserveDiagnostics(_ => calls++);
Measure(bus);
var allocated = Measure(bus);
Assert.That(calls, Is.EqualTo(20000));
Assert.That(allocated, Is.Zero);
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
private static long Measure(IShrinkEventBus bus)
{
var before = GC.GetAllocatedBytesForCurrentThread();
for (var i = 0; i < 10000; i++) bus.Post(new ProbeEvent());
return GC.GetAllocatedBytesForCurrentThread() - before;
}
}