fix(comm): single-gRPC-endpoint sites can go live (flip degenerates to same-node reconnect) (plan R2-02 T15)
This commit is contained in:
@@ -258,4 +258,48 @@ public class SiteAlarmLiveCacheServiceTests : TestKit
|
||||
Assert.False(service.IsLive(999));
|
||||
Assert.Empty(service.GetCurrentAlarms(999));
|
||||
}
|
||||
|
||||
// ── R2 T15: single-endpoint sites can go live (N9) ──
|
||||
|
||||
[Fact]
|
||||
public void SiteWithOnlyNodeAEndpoint_StartsAnAggregator_AgainstThatEndpoint()
|
||||
{
|
||||
var site = new Site("Three", "site-3")
|
||||
{
|
||||
Id = 3,
|
||||
GrpcNodeAAddress = "http://only-node:8083",
|
||||
GrpcNodeBAddress = null, // single-endpoint site — pre-fix: never goes live
|
||||
};
|
||||
|
||||
var siteRepo = Substitute.For<ISiteRepository>();
|
||||
siteRepo.GetSiteByIdAsync(3, Arg.Any<CancellationToken>()).Returns(site);
|
||||
|
||||
var instanceRepo = Substitute.For<ITemplateEngineRepository>();
|
||||
instanceRepo.GetInstancesBySiteIdAsync(3, Arg.Any<CancellationToken>())
|
||||
.Returns(new List<Instance>());
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddScoped(_ => siteRepo);
|
||||
services.AddScoped(_ => instanceRepo);
|
||||
var provider = services.BuildServiceProvider();
|
||||
|
||||
var options = Options.Create(new CommunicationOptions
|
||||
{
|
||||
LiveAlarmCacheLinger = TimeSpan.FromSeconds(30),
|
||||
LiveAlarmCacheReconcileInterval = TimeSpan.FromMinutes(10),
|
||||
});
|
||||
var comm = new CommunicationService(Options.Create(new CommunicationOptions()),
|
||||
NullLogger<CommunicationService>.Instance);
|
||||
var factory = new CountingFactory();
|
||||
|
||||
var service = new SiteAlarmLiveCacheService(
|
||||
provider, comm, factory, options, NullLogger<SiteAlarmLiveCacheService>.Instance);
|
||||
service.SetActorSystem(Sys);
|
||||
|
||||
using var sub = service.Subscribe(3, () => { });
|
||||
|
||||
// Pre-fix: ResolveSiteAsync required BOTH endpoints and bailed → never live, no client.
|
||||
AwaitCondition(() => service.IsLive(3), TimeSpan.FromSeconds(5));
|
||||
Assert.True(factory.GetOrCreateCount >= 1); // a client was created for the single endpoint
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user