1ee2e171cf
`health pending-updates` (#63) called IPendingUpdatesEvaluator.EvaluateAsync directly from ManagementActor because the cache lived in CentralUI, so every CLI call was a full uncached fleet flatten. IPendingUpdatesCache/PendingUpdatesCache now live in DeploymentManager.PendingUpdates and are registered by AddDeploymentManager; the SingleFlightMemo<T> primitive moves to Commons.Caching (public) so both CentralUI's KPI / alarm-summary caches and DeploymentManager can use it. HandleGetPendingUpdates reads the shared cache; the UI circuits and the CLI now share one memo per node. Tests: ManagementActor repeated-calls test (fails against the direct evaluator call: 2 evaluations instead of 1), AddDeploymentManager singleton-registration test; the cache and memo tests move with their types. (ScadaBridge#91) Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
107 lines
4.6 KiB
C#
107 lines
4.6 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.DeploymentManager.Tests;
|
|
|
|
/// <summary>
|
|
/// DeploymentManagerOptions must be resolvable via the
|
|
/// Options pattern and bindable to the "ScadaBridge:DeploymentManager"
|
|
/// configuration section. The component itself does not depend on
|
|
/// IConfiguration (enforced by Host's OptionsTests) — the Host binds the
|
|
/// section; AddDeploymentManager only guarantees IOptions resolvability.
|
|
/// </summary>
|
|
public class ServiceCollectionExtensionsTests
|
|
{
|
|
/// <summary>Verifies that AddDeploymentManager registers resolvable options with default values.</summary>
|
|
[Fact]
|
|
public void AddDeploymentManager_RegistersResolvableOptions_WithDefaults()
|
|
{
|
|
var services = new ServiceCollection();
|
|
services.AddDeploymentManager();
|
|
|
|
using var provider = services.BuildServiceProvider();
|
|
var options = provider.GetRequiredService<IOptions<DeploymentManagerOptions>>().Value;
|
|
|
|
// No section bound -> the option-class defaults are retained.
|
|
Assert.Equal(TimeSpan.FromSeconds(5), options.OperationLockTimeout);
|
|
}
|
|
|
|
/// <summary>Verifies that the options bind to the configuration section the way the host wires them.</summary>
|
|
[Fact]
|
|
public void AddDeploymentManager_OptionsBindToConfigurationSection_AsTheHostWires()
|
|
{
|
|
// Mirrors the Host wiring: the Host calls Configure<DeploymentManagerOptions>
|
|
// against OptionsSection, then AddDeploymentManager().
|
|
var configuration = new ConfigurationBuilder()
|
|
.AddInMemoryCollection(new Dictionary<string, string?>
|
|
{
|
|
["ScadaBridge:DeploymentManager:OperationLockTimeout"] = "00:00:09",
|
|
["ScadaBridge:DeploymentManager:ArtifactDeploymentTimeoutPerSite"] = "00:03:00"
|
|
})
|
|
.Build();
|
|
|
|
var services = new ServiceCollection();
|
|
services.Configure<DeploymentManagerOptions>(
|
|
configuration.GetSection(ServiceCollectionExtensions.OptionsSection));
|
|
services.AddDeploymentManager();
|
|
|
|
using var provider = services.BuildServiceProvider();
|
|
var options = provider.GetRequiredService<IOptions<DeploymentManagerOptions>>().Value;
|
|
|
|
Assert.Equal(TimeSpan.FromSeconds(9), options.OperationLockTimeout);
|
|
Assert.Equal(TimeSpan.FromMinutes(3), options.ArtifactDeploymentTimeoutPerSite);
|
|
}
|
|
|
|
/// <summary>Verifies that the options section name matches the conventional component section path.</summary>
|
|
[Fact]
|
|
public void OptionsSection_MatchesTheConventionalComponentSectionPath()
|
|
{
|
|
Assert.Equal("ScadaBridge:DeploymentManager", ServiceCollectionExtensions.OptionsSection);
|
|
}
|
|
|
|
// The deployment-status notifier must be a singleton so the
|
|
// scoped DeploymentService and the Central UI's scoped Blazor page share
|
|
// one instance — without that, a push notification raised by the service
|
|
// would never reach the page's subscription.
|
|
/// <summary>Verifies that AddDeploymentManager registers the deployment status notifier as a singleton.</summary>
|
|
[Fact]
|
|
public void AddDeploymentManager_RegistersDeploymentStatusNotifier_AsSingleton()
|
|
{
|
|
var services = new ServiceCollection();
|
|
services.AddLogging();
|
|
services.AddDeploymentManager();
|
|
|
|
using var provider = services.BuildServiceProvider();
|
|
|
|
var fromRoot = provider.GetRequiredService<IDeploymentStatusNotifier>();
|
|
using var scope = provider.CreateScope();
|
|
var fromScope = scope.ServiceProvider.GetRequiredService<IDeploymentStatusNotifier>();
|
|
|
|
Assert.IsType<DeploymentStatusNotifier>(fromRoot);
|
|
Assert.Same(fromRoot, fromScope);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gitea #91: the pending-updates cache is registered by AddDeploymentManager (not the
|
|
/// Central UI) as ONE process-wide singleton, so the UI circuits and the management API's
|
|
/// GetPendingUpdatesCommand share a single memo.
|
|
/// </summary>
|
|
[Fact]
|
|
public void AddDeploymentManager_RegistersPendingUpdatesCache_AsSingleton()
|
|
{
|
|
var services = new ServiceCollection();
|
|
services.AddLogging();
|
|
services.AddDeploymentManager();
|
|
|
|
using var provider = services.BuildServiceProvider();
|
|
|
|
var fromRoot = provider.GetRequiredService<PendingUpdates.IPendingUpdatesCache>();
|
|
using var scope = provider.CreateScope();
|
|
var fromScope = scope.ServiceProvider.GetRequiredService<PendingUpdates.IPendingUpdatesCache>();
|
|
|
|
Assert.IsType<PendingUpdates.PendingUpdatesCache>(fromRoot);
|
|
Assert.Same(fromRoot, fromScope);
|
|
}
|
|
}
|