Premiere commit - Omika
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
using Omika.Core.Observability.Diagnostic;
|
||||
|
||||
namespace Omika.Tests.Observability.Diagnostic;
|
||||
|
||||
public class BreadcrumbServiceTests
|
||||
{
|
||||
[Fact]
|
||||
public void Capacity100_Add150_CountIs100_OldestDropped()
|
||||
{
|
||||
var service = new BreadcrumbService(100);
|
||||
|
||||
for (int i = 0; i < 150; i++)
|
||||
{
|
||||
service.Add(new Breadcrumb { Code = "B" + i });
|
||||
}
|
||||
|
||||
Assert.Equal(100, service.Count);
|
||||
IReadOnlyList<Breadcrumb> snapshot = service.Snapshot();
|
||||
Assert.Equal(100, snapshot.Count);
|
||||
// Les 50 plus anciens (B0..B49) sont supprimés.
|
||||
Assert.Equal("B50", snapshot[0].Code);
|
||||
Assert.Equal("B149", snapshot[^1].Code);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NullBreadcrumb_DoesNotThrow()
|
||||
{
|
||||
var service = new BreadcrumbService(10);
|
||||
|
||||
service.Add(null!);
|
||||
|
||||
Assert.Equal(0, service.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ConcurrentAdds_AreBounded_AndNeverThrow()
|
||||
{
|
||||
var service = new BreadcrumbService(100);
|
||||
|
||||
Parallel.For(0, 1000, i => service.Add(new Breadcrumb { Code = "C" + i }));
|
||||
|
||||
Assert.True(service.Count <= 100);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TraceContext_AddsTraceIdAutomatically()
|
||||
{
|
||||
var trace = new TraceContext();
|
||||
var service = new BreadcrumbService(10, trace);
|
||||
|
||||
Guid traceId;
|
||||
using (trace.BeginTrace())
|
||||
{
|
||||
traceId = trace.CurrentTraceId!.Value;
|
||||
service.Add(new Breadcrumb { Code = "NAVIGATION", Target = "RendezVousDetail" });
|
||||
}
|
||||
|
||||
Assert.Equal(traceId, service.Snapshot().Single().TraceId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user