Files
Heimdall/tests/Heimdall.Application.Tests/Metrics/HeimdallMetricsTests.cs
T

143 lines
3.7 KiB
C#

using Heimdall.Application.Metrics;
namespace Heimdall.Application.Tests.Metrics;
public class HeimdallMetricsTests
{
public HeimdallMetricsTests()
{
HeimdallMetrics.ResetForTesting();
}
[Fact]
public void Meter_Should_Have_Correct_Name()
{
HeimdallMetrics.Meter.Name.ShouldBe(HeimdallMetrics.MeterName);
}
[Fact]
public void RecordEventCreated_Should_Not_Throw()
{
var act = () => HeimdallMetrics.RecordEventCreated("MotionDetected");
act.ShouldNotThrow();
}
[Fact]
public void RecordEventCreated_With_Tags_Should_Not_Throw()
{
var act = () => HeimdallMetrics.RecordEventCreated(
"PersonDetected",
cameraId: Guid.NewGuid(),
siteId: Guid.NewGuid());
act.ShouldNotThrow();
}
[Fact]
public void RecordEventSuppressed_Should_Not_Throw()
{
var act = () => HeimdallMetrics.RecordEventSuppressed("cooldown", "MotionDetected");
act.ShouldNotThrow();
}
[Fact]
public void SetPipelineLevel_Should_Update_Value()
{
HeimdallMetrics.SetPipelineLevel(2);
var act = () => HeimdallMetrics.SetPipelineLevel(0);
act.ShouldNotThrow();
}
[Fact]
public void SetSnapshotInterval_Should_Accept_TimeSpan()
{
var act = () => HeimdallMetrics.SetSnapshotInterval(TimeSpan.FromMilliseconds(500));
act.ShouldNotThrow();
}
[Fact]
public void RecordYoloInference_Should_Not_Throw()
{
var act = () => HeimdallMetrics.RecordYoloInference(42.5, detectionCount: 3);
act.ShouldNotThrow();
}
[Fact]
public void RecordYoloInference_Without_DetectionCount_Should_Not_Throw()
{
var act = () => HeimdallMetrics.RecordYoloInference(10.0);
act.ShouldNotThrow();
}
[Fact]
public void RecordInference_Should_Not_Throw()
{
var act = () => HeimdallMetrics.RecordInference(55.0, modelLoaded: true);
act.ShouldNotThrow();
}
[Fact]
public void SetQueueDepth_Should_Update_Value()
{
var act = () => HeimdallMetrics.SetQueueDepth(42);
act.ShouldNotThrow();
}
[Fact]
public void SignalRConnectionAdded_Should_Increment()
{
var act = () =>
{
HeimdallMetrics.SignalRConnectionAdded();
HeimdallMetrics.SignalRConnectionAdded();
};
act.ShouldNotThrow();
}
[Fact]
public void SignalRConnectionRemoved_Should_Decrement()
{
var act = () =>
{
HeimdallMetrics.SignalRConnectionAdded();
HeimdallMetrics.SignalRConnectionRemoved();
};
act.ShouldNotThrow();
}
[Fact]
public void ViewerAdded_Should_Not_Throw()
{
var act = () => HeimdallMetrics.ViewerAdded();
act.ShouldNotThrow();
}
[Fact]
public void ViewerRemoved_Should_Not_Throw()
{
var act = () =>
{
HeimdallMetrics.ViewerAdded();
HeimdallMetrics.ViewerRemoved();
};
act.ShouldNotThrow();
}
[Fact]
public void ResetForTesting_Should_Reset_All_Counters()
{
HeimdallMetrics.SignalRConnectionAdded();
HeimdallMetrics.SignalRConnectionAdded();
HeimdallMetrics.ViewerAdded();
HeimdallMetrics.SetQueueDepth(10);
HeimdallMetrics.SetPipelineLevel(2);
HeimdallMetrics.ResetForTesting();
// After reset, adding and removing should return to 0 without exception
HeimdallMetrics.SignalRConnectionAdded();
HeimdallMetrics.SignalRConnectionRemoved();
HeimdallMetrics.ViewerAdded();
HeimdallMetrics.ViewerRemoved();
}
}