c4186509f6
Interface now lives in Commons.Interfaces.Services; AuditLog no longer gets it transitively through Communication. Implementation stays in HealthMonitoring. Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
68 lines
2.7 KiB
C#
68 lines
2.7 KiB
C#
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Services;
|
|
namespace ZB.MOM.WW.ScadaBridge.HealthMonitoring.Tests;
|
|
|
|
/// <summary>
|
|
/// Regression coverage. <see cref="ISiteEventLogger.FailedWriteCount"/>
|
|
/// is a cumulative (point-in-time) counter. A periodic
|
|
/// <c>SiteEventLogFailureCountReporter</c> hosted service polls the count and
|
|
/// pushes it into the collector via
|
|
/// <see cref="ISiteHealthCollector.SetSiteEventLogWriteFailures"/> so the next
|
|
/// <see cref="ISiteHealthCollector.CollectReport"/> includes it in the report
|
|
/// payload as <c>SiteEventLogWriteFailures</c>. Unlike the per-interval
|
|
/// SiteAuditWriteFailures counter, this value is NOT reset on collect — it
|
|
/// carries forward whatever the most recent poller push delivered.
|
|
/// </summary>
|
|
public class SiteEventLogWriteFailuresMetricTests
|
|
{
|
|
private readonly SiteHealthCollector _collector = new();
|
|
|
|
/// <summary>Verifies that a count that was set appears in the collected report.</summary>
|
|
[Fact]
|
|
public void Set_Then_CollectReport_IncludesCount()
|
|
{
|
|
_collector.SetSiteEventLogWriteFailures(17L);
|
|
|
|
var report = _collector.CollectReport("site-1");
|
|
|
|
Assert.Equal(17L, report.SiteEventLogWriteFailures);
|
|
}
|
|
|
|
/// <summary>Verifies that the report payload includes the site event log write failure count, defaulting to zero.</summary>
|
|
[Fact]
|
|
public void Report_Payload_Includes_SiteEventLogWriteFailures_AsZeroByDefault()
|
|
{
|
|
var report = _collector.CollectReport("site-1");
|
|
|
|
Assert.Equal(0L, report.SiteEventLogWriteFailures);
|
|
}
|
|
|
|
/// <summary>Verifies that collecting a report does not reset the site event log write failure count.</summary>
|
|
[Fact]
|
|
public void CollectReport_DoesNotReset_SiteEventLogWriteFailures()
|
|
{
|
|
// This is a point-in-time cumulative count — successive CollectReport
|
|
// calls before the next poller tick MUST carry forward the same value
|
|
// rather than resetting to zero (which would falsely indicate no failures
|
|
// between the two reports).
|
|
_collector.SetSiteEventLogWriteFailures(42L);
|
|
|
|
var first = _collector.CollectReport("site-1");
|
|
var second = _collector.CollectReport("site-1");
|
|
|
|
Assert.Equal(42L, first.SiteEventLogWriteFailures);
|
|
Assert.Equal(42L, second.SiteEventLogWriteFailures);
|
|
}
|
|
|
|
/// <summary>Verifies that setting the count overwrites the previous value.</summary>
|
|
[Fact]
|
|
public void Set_Overwrites_Previous_Value()
|
|
{
|
|
_collector.SetSiteEventLogWriteFailures(5L);
|
|
_collector.SetSiteEventLogWriteFailures(9L);
|
|
|
|
var report = _collector.CollectReport("site-1");
|
|
|
|
Assert.Equal(9L, report.SiteEventLogWriteFailures);
|
|
}
|
|
}
|