using System.Reflection; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; using ZB.MOM.WW.ScadaBridge.ClusterInfrastructure; using ZB.MOM.WW.ScadaBridge.Host; using ZB.MOM.WW.ScadaBridge.Host.Actors; namespace ZB.MOM.WW.ScadaBridge.Host.Tests; public class BootstrapCancellationTests { /// Verifies that a cancelled bootstrap neither resolves the actor system nor joins the cluster. /// A task that represents the asynchronous operation. [Fact] public async Task CancelledBootstrap_DoesNotResolveActorSystemOrJoin() { var accessed = 0; var coordinator = new ClusterBootstrapCoordinator( () => { accessed++; throw new InvalidOperationException("must not resolve during shutdown"); }, Options.Create(new ClusterOptions { SeedNodes = ["akka.tcp://scadabridge@127.0.0.1:2551"] }), Options.Create(new NodeOptions { NodeHostname = "127.0.0.1", RemotingPort = 2551 }), NullLogger.Instance); var run = typeof(ClusterBootstrapCoordinator).GetMethod("RunAsync", BindingFlags.Instance | BindingFlags.NonPublic)!; await (Task)run.Invoke(coordinator, [new CancellationToken(true)])!; Assert.Equal(0, accessed); } }