513fa1aa16
Comment/XML-doc changes only: - add summaries to ~10k test methods, fixtures, fakes and helpers (+ <param> on theories, <returns> on async Task methods, <inheritdoc/> on interface implementations the checker can resolve) - strip ~2.6k project-tracking references (WP*, P*-*, row-NN, Task N, #NN, Component-0NN) from comments, keeping the explanatory text; reword false positives in comments only - real docs on fakes implementing BCL/library interfaces (IDisposable, ILogger, IOptionsMonitor, IAsyncLifetime) - reword the last 5 src/ false positives (CWE-1236, failures-1, year-0001, M365) Only non-comment edits: four one-line nested classes split across lines so members can carry docs. Build 0 errors / 0 warnings.
54 lines
2.5 KiB
C#
54 lines
2.5 KiB
C#
using Akka.Actor;
|
|
using Akka.TestKit.Xunit2;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using NSubstitute;
|
|
using Xunit;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Sites;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories;
|
|
using ZB.MOM.WW.ScadaBridge.Communication.Actors;
|
|
using ZB.MOM.WW.ScadaBridge.HealthMonitoring;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.Communication.Tests;
|
|
|
|
/// <summary>
|
|
/// Transport-agnostic refresh behaviour of <see cref="CentralCommunicationActor"/>: the periodic
|
|
/// DB refresh evicts deleted sites from the health aggregator. The two former tests here —
|
|
/// per-site ClusterClient recreate-without-restart-loop and factory-throw resilience — asserted
|
|
/// Akka <c>AkkaSiteTransport</c> internals (InvalidActorNameException, "No ClusterClient for site")
|
|
/// and were removed with that transport in the ClusterClient→gRPC migration's Phase 4; the
|
|
/// equivalent gRPC channel reconcile is covered by the <c>GrpcSiteTransport</c> suites.
|
|
/// </summary>
|
|
public class CentralCommunicationActorClientLifecycleTests : TestKit
|
|
{
|
|
/// <summary>Verifies that periodic refresh prunes deleted sites from health aggregator.</summary>
|
|
[Fact]
|
|
public void PeriodicRefresh_PrunesDeletedSites_FromHealthAggregator()
|
|
{
|
|
// The periodic site refresh feeds the currently-configured
|
|
// site ids to the aggregator so a deleted site is evicted within one
|
|
// refresh interval. Repo returns only "site-a".
|
|
var siteRepo = Substitute.For<ISiteRepository>();
|
|
siteRepo.GetAllSitesAsync(Arg.Any<CancellationToken>())
|
|
.Returns(new List<Site> { new("Site A", "site-a") });
|
|
var aggregator = Substitute.For<ICentralHealthAggregator>();
|
|
var services = new ServiceCollection();
|
|
services.AddScoped(_ => siteRepo);
|
|
services.AddSingleton(aggregator);
|
|
var provider = services.BuildServiceProvider();
|
|
|
|
var transport = Substitute.For<ISiteCommandTransport>();
|
|
var actor = Sys.ActorOf(Props.Create(() => new CentralCommunicationActor(
|
|
provider, transport)));
|
|
|
|
// Trigger the refresh (also fires at PreStart, but drive it explicitly so
|
|
// the assertion is deterministic). The load runs on a detached task and
|
|
// pipes SiteAddressCacheLoaded back to the actor, which then prunes.
|
|
actor.Tell(new RefreshSiteAddresses());
|
|
|
|
AwaitAssert(
|
|
() => aggregator.Received().PruneUnknownSites(
|
|
Arg.Is<IReadOnlyCollection<string>>(ids => ids.Contains("site-a"))),
|
|
TimeSpan.FromSeconds(3));
|
|
}
|
|
}
|