73 lines
2.7 KiB
C++
73 lines
2.7 KiB
C++
#include "HealthTelemetry.h"
|
|
|
|
#include <iostream>
|
|
|
|
namespace
|
|
{
|
|
int gFailures = 0;
|
|
|
|
void Expect(bool condition, const char* message)
|
|
{
|
|
if (condition)
|
|
return;
|
|
|
|
std::cerr << "FAIL: " << message << "\n";
|
|
++gFailures;
|
|
}
|
|
|
|
void TestRuntimeEventQueueMetrics()
|
|
{
|
|
HealthTelemetry telemetry;
|
|
telemetry.RecordRuntimeEventQueueMetrics("runtime-events", 3, 64, 2, 12.5);
|
|
|
|
const HealthTelemetry::RuntimeEventMetricsSnapshot metrics = telemetry.GetRuntimeEventMetricsSnapshot();
|
|
Expect(metrics.queue.queueName == "runtime-events", "queue metrics store queue name");
|
|
Expect(metrics.queue.depth == 3, "queue metrics store depth");
|
|
Expect(metrics.queue.capacity == 64, "queue metrics store capacity");
|
|
Expect(metrics.queue.droppedCount == 2, "queue metrics store dropped count");
|
|
Expect(metrics.queue.oldestEventAgeMilliseconds == 12.5, "queue metrics store oldest event age");
|
|
}
|
|
|
|
void TestRuntimeEventDispatchStats()
|
|
{
|
|
HealthTelemetry telemetry;
|
|
telemetry.RecordRuntimeEventDispatchStats(2, 5, 1, 0.75);
|
|
telemetry.RecordRuntimeEventDispatchStats(3, 6, 0, 0.25);
|
|
|
|
const HealthTelemetry::Snapshot snapshot = telemetry.GetSnapshot();
|
|
Expect(snapshot.runtimeEvents.dispatch.dispatchCallCount == 2, "dispatch stats count dispatch calls");
|
|
Expect(snapshot.runtimeEvents.dispatch.dispatchedEventCount == 5, "dispatch stats accumulate dispatched events");
|
|
Expect(snapshot.runtimeEvents.dispatch.handlerInvocationCount == 11, "dispatch stats accumulate handler invocations");
|
|
Expect(snapshot.runtimeEvents.dispatch.handlerFailureCount == 1, "dispatch stats accumulate handler failures");
|
|
Expect(snapshot.runtimeEvents.dispatch.lastDispatchDurationMilliseconds == 0.25, "dispatch stats store latest duration");
|
|
Expect(snapshot.runtimeEvents.dispatch.maxDispatchDurationMilliseconds == 0.75, "dispatch stats store max duration");
|
|
}
|
|
|
|
void TestRuntimeEventTryRecord()
|
|
{
|
|
HealthTelemetry telemetry;
|
|
Expect(telemetry.TryRecordRuntimeEventQueueMetrics("runtime-events", 1, 4, 0, -5.0), "try queue metrics succeeds when uncontended");
|
|
Expect(telemetry.TryRecordRuntimeEventDispatchStats(1, 2, 0, -1.0), "try dispatch stats succeeds when uncontended");
|
|
|
|
const HealthTelemetry::RuntimeEventMetricsSnapshot metrics = telemetry.GetRuntimeEventMetricsSnapshot();
|
|
Expect(metrics.queue.oldestEventAgeMilliseconds == 0.0, "queue age is clamped to non-negative values");
|
|
Expect(metrics.dispatch.lastDispatchDurationMilliseconds == 0.0, "dispatch duration is clamped to non-negative values");
|
|
}
|
|
}
|
|
|
|
int main()
|
|
{
|
|
TestRuntimeEventQueueMetrics();
|
|
TestRuntimeEventDispatchStats();
|
|
TestRuntimeEventTryRecord();
|
|
|
|
if (gFailures != 0)
|
|
{
|
|
std::cerr << gFailures << " HealthTelemetry test failure(s).\n";
|
|
return 1;
|
|
}
|
|
|
|
std::cout << "HealthTelemetry tests passed.\n";
|
|
return 0;
|
|
}
|