4cd21b342b
Consolidates the reporter's poll cadence onto SqliteAuditWriterOptions instead of the hard-coded 30 s constant, closing deferred-work register item #21 (the config- shape cleanup its own XML doc flagged as a follow-up). - SqliteAuditWriterOptions.BacklogPollIntervalSeconds (default 30). - Reporter reads it via IOptions; precedence explicit-override (tests) > configured > 30 s default; a non-positive value falls back to the default. Corrected the stale "hard-code / tunable in a follow-up" class-doc. - Cadence tests + register updated (row 21 -> Resolved). Claude-Session: https://claude.ai/code/session_01MtdgwpEeCUn6cUA5f1LMPj
64 lines
2.1 KiB
C#
64 lines
2.1 KiB
C#
using Microsoft.Extensions.Logging.Abstractions;
|
|
using Microsoft.Extensions.Options;
|
|
using NSubstitute;
|
|
using ZB.MOM.WW.ScadaBridge.AuditLog.Site;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Services;
|
|
using ZB.MOM.WW.ScadaBridge.HealthMonitoring;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.AuditLog.Tests.Site;
|
|
|
|
/// <summary>
|
|
/// Deferred-work #21: the backlog reporter's poll cadence is configurable via
|
|
/// <see cref="SqliteAuditWriterOptions.BacklogPollIntervalSeconds"/> instead of the
|
|
/// old hard-coded 30 s constant.
|
|
/// </summary>
|
|
public class SiteAuditBacklogReporterCadenceTests
|
|
{
|
|
private static SiteAuditBacklogReporter Create(
|
|
IOptions<SqliteAuditWriterOptions>? options, TimeSpan? explicitInterval = null) =>
|
|
new(
|
|
Substitute.For<ISiteAuditQueue>(),
|
|
Substitute.For<ISiteHealthCollector>(),
|
|
NullLogger<SiteAuditBacklogReporter>.Instance,
|
|
explicitInterval,
|
|
options);
|
|
|
|
[Fact]
|
|
public void Cadence_ComesFromOptions_WhenConfigured()
|
|
{
|
|
var options = Options.Create(new SqliteAuditWriterOptions { BacklogPollIntervalSeconds = 12 });
|
|
|
|
var reporter = Create(options);
|
|
|
|
Assert.Equal(TimeSpan.FromSeconds(12), reporter.RefreshInterval);
|
|
}
|
|
|
|
[Fact]
|
|
public void Cadence_FallsBackToDefault_WhenOptionsNonPositive()
|
|
{
|
|
var options = Options.Create(new SqliteAuditWriterOptions { BacklogPollIntervalSeconds = 0 });
|
|
|
|
var reporter = Create(options);
|
|
|
|
Assert.Equal(SiteAuditBacklogReporter.DefaultRefreshInterval, reporter.RefreshInterval);
|
|
}
|
|
|
|
[Fact]
|
|
public void Cadence_FallsBackToDefault_WhenNoOptions()
|
|
{
|
|
var reporter = Create(options: null);
|
|
|
|
Assert.Equal(SiteAuditBacklogReporter.DefaultRefreshInterval, reporter.RefreshInterval);
|
|
}
|
|
|
|
[Fact]
|
|
public void ExplicitInterval_WinsOverOptions()
|
|
{
|
|
var options = Options.Create(new SqliteAuditWriterOptions { BacklogPollIntervalSeconds = 12 });
|
|
|
|
var reporter = Create(options, explicitInterval: TimeSpan.FromSeconds(3));
|
|
|
|
Assert.Equal(TimeSpan.FromSeconds(3), reporter.RefreshInterval);
|
|
}
|
|
}
|