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.
97 lines
4.6 KiB
C#
97 lines
4.6 KiB
C#
using Akka.Actor;
|
|
using Akka.TestKit.Xunit2;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using NSubstitute;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories;
|
|
using ZB.MOM.WW.ScadaBridge.Communication.Actors;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.Communication.Tests;
|
|
|
|
/// <summary>
|
|
/// Regression tests that coordinator actors must declare an
|
|
/// explicit <c>Resume</c> supervision strategy per the CLAUDE.md decision
|
|
/// ("Resume for coordinator actors"). A child fault under the default
|
|
/// (Restart) strategy would wipe a child's in-memory state; the long-lived
|
|
/// coordinators own per-site transport resources and must not silently discard
|
|
/// their children on a transient fault.
|
|
/// </summary>
|
|
public class CoordinatorSupervisionTests : TestKit
|
|
{
|
|
/// <summary>
|
|
/// Test-only subclass that exposes the protected <see cref="SupervisorStrategy"/>
|
|
/// so the configured directive can be asserted directly.
|
|
/// </summary>
|
|
private sealed class CentralCommunicationActorProbe : CentralCommunicationActor
|
|
{
|
|
/// <summary>Initializes the probe with the dependencies required by the central communication actor.</summary>
|
|
/// <param name="sp">The service provider passed to the base actor.</param>
|
|
/// <param name="transport">The site command transport passed to the base actor.</param>
|
|
public CentralCommunicationActorProbe(IServiceProvider sp, ISiteCommandTransport transport)
|
|
: base(sp, transport) { }
|
|
|
|
/// <summary>Returns the actor's configured supervisor strategy.</summary>
|
|
/// <returns>The supervisor strategy declared by the actor.</returns>
|
|
public SupervisorStrategy GetSupervisorStrategy() => SupervisorStrategy();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Test-only subclass that exposes the protected <see cref="SupervisorStrategy"/>.
|
|
/// </summary>
|
|
private sealed class SiteCommunicationActorProbe : SiteCommunicationActor
|
|
{
|
|
/// <summary>Initializes the probe with the dependencies required by the site communication actor.</summary>
|
|
/// <param name="siteId">The site identifier passed to the base actor.</param>
|
|
/// <param name="options">The communication options passed to the base actor.</param>
|
|
/// <param name="dm">The deployment manager reference passed to the base actor.</param>
|
|
public SiteCommunicationActorProbe(string siteId, CommunicationOptions options, IActorRef dm)
|
|
: base(siteId, options, dm) { }
|
|
|
|
/// <summary>Returns the actor's configured supervisor strategy.</summary>
|
|
/// <returns>The supervisor strategy declared by the actor.</returns>
|
|
public SupervisorStrategy GetSupervisorStrategy() => SupervisorStrategy();
|
|
}
|
|
|
|
private static IServiceProvider EmptyServiceProvider()
|
|
{
|
|
var mockRepo = Substitute.For<ISiteRepository>();
|
|
mockRepo.GetAllSitesAsync(Arg.Any<CancellationToken>())
|
|
.Returns(new List<Commons.Entities.Sites.Site>());
|
|
var services = new ServiceCollection();
|
|
services.AddScoped(_ => mockRepo);
|
|
return services.BuildServiceProvider();
|
|
}
|
|
|
|
/// <summary>Verifies that the central communication actor declares a Resume supervisor strategy.</summary>
|
|
[Fact]
|
|
public void CentralCommunicationActor_SupervisorStrategy_IsResume()
|
|
{
|
|
var sp = EmptyServiceProvider();
|
|
var transport = Substitute.For<ISiteCommandTransport>();
|
|
|
|
var actorRef = new Akka.TestKit.TestActorRef<CentralCommunicationActorProbe>(
|
|
Sys, Props.Create(() => new CentralCommunicationActorProbe(sp, transport)));
|
|
|
|
var strategy = actorRef.UnderlyingActor.GetSupervisorStrategy();
|
|
|
|
var oneForOne = Assert.IsType<OneForOneStrategy>(strategy);
|
|
var directive = oneForOne.Decider.Decide(new InvalidOperationException("transient child fault"));
|
|
Assert.Equal(Directive.Resume, directive);
|
|
}
|
|
|
|
/// <summary>Verifies that the site communication actor declares a Resume supervisor strategy.</summary>
|
|
[Fact]
|
|
public void SiteCommunicationActor_SupervisorStrategy_IsResume()
|
|
{
|
|
var dmProbe = CreateTestProbe();
|
|
|
|
var actorRef = new Akka.TestKit.TestActorRef<SiteCommunicationActorProbe>(
|
|
Sys, Props.Create(() => new SiteCommunicationActorProbe("site1", new CommunicationOptions(), dmProbe.Ref)));
|
|
|
|
var strategy = actorRef.UnderlyingActor.GetSupervisorStrategy();
|
|
|
|
var oneForOne = Assert.IsType<OneForOneStrategy>(strategy);
|
|
var directive = oneForOne.Decider.Decide(new InvalidOperationException("transient child fault"));
|
|
Assert.Equal(Directive.Resume, directive);
|
|
}
|
|
}
|