Files
ScadaBridge/tests/ZB.MOM.WW.ScadaBridge.DeploymentManager.Tests/DeploymentManagerOptionsValidatorTests.cs
T
Joseph Doherty fc48db480c feat(deploy): PendingUpdatesEvaluator — one fleet snapshot of stale instances and stale-artifact sites
One scoped read that answers "is anything waiting to be deployed?" for the whole
fleet: each site's stored artifact revision hash compared against what a deploy
would send right now (NeverDeployed / Current / OutOfDate), plus per-site
deployed/stale/unknown instance tallies from the batched staleness evaluation.
NeverDeployed is deliberately NOT a pending update — the operator has not deployed
yet — and exceptions propagate so the caller's single-flight cache can render
"unavailable" rather than invent an "up to date". Adds the validated
PendingUpdatesCacheTtl (60 s) that TTL will key off.

Claude-Session: https://claude.ai/code/session_01Y5ef34iUUMjmwnMpL9xgmB
2026-09-14 13:49:54 -04:00

98 lines
3.7 KiB
C#

using Microsoft.Extensions.Options;
namespace ZB.MOM.WW.ScadaBridge.DeploymentManager.Tests;
/// <summary>
/// Arch-review 08 §1.5: <see cref="DeploymentManagerOptions"/> timeouts are
/// applied as linked-CTS deadlines around lifecycle commands, per-site artifact
/// deployment, and operation-lock acquisition. A zero/negative duration makes a
/// deadline fire immediately (or a <c>CancellationTokenSource</c> constructor
/// throw), so a misconfigured section must be rejected at startup with a clear,
/// key-naming message rather than silently breaking deployments.
/// </summary>
public class DeploymentManagerOptionsValidatorTests
{
private static ValidateOptionsResult Validate(DeploymentManagerOptions options) =>
new DeploymentManagerOptionsValidator().Validate(Options.DefaultName, options);
[Fact]
public void DefaultOptions_AreValid()
{
var result = Validate(new DeploymentManagerOptions());
Assert.True(result.Succeeded, result.FailureMessage);
}
[Fact]
public void ZeroLifecycleCommandTimeout_IsRejected()
{
var result = Validate(new DeploymentManagerOptions { LifecycleCommandTimeout = TimeSpan.Zero });
Assert.True(result.Failed);
Assert.Contains("LifecycleCommandTimeout", result.FailureMessage);
}
[Fact]
public void NegativeLifecycleCommandTimeout_IsRejected()
{
var result = Validate(new DeploymentManagerOptions { LifecycleCommandTimeout = TimeSpan.FromSeconds(-1) });
Assert.True(result.Failed);
Assert.Contains("LifecycleCommandTimeout", result.FailureMessage);
}
[Fact]
public void ZeroArtifactDeploymentTimeoutPerSite_IsRejected()
{
var result = Validate(new DeploymentManagerOptions { ArtifactDeploymentTimeoutPerSite = TimeSpan.Zero });
Assert.True(result.Failed);
Assert.Contains("ArtifactDeploymentTimeoutPerSite", result.FailureMessage);
}
[Fact]
public void ZeroOperationLockTimeout_IsRejected()
{
var result = Validate(new DeploymentManagerOptions { OperationLockTimeout = TimeSpan.Zero });
Assert.True(result.Failed);
Assert.Contains("OperationLockTimeout", result.FailureMessage);
}
[Fact]
public void ZeroSiteDeploymentReconcileTimeout_IsRejected()
{
var result = Validate(new DeploymentManagerOptions { SiteDeploymentReconcileTimeout = TimeSpan.Zero });
Assert.True(result.Failed);
Assert.Contains("SiteDeploymentReconcileTimeout", result.FailureMessage);
}
[Fact]
public void NegativeSiteDeploymentReconcileTimeout_IsRejected()
{
var result = Validate(new DeploymentManagerOptions
{
SiteDeploymentReconcileTimeout = TimeSpan.FromSeconds(-1)
});
Assert.True(result.Failed);
Assert.Contains("SiteDeploymentReconcileTimeout", result.FailureMessage);
}
[Fact]
public void ZeroPendingUpdatesCacheTtl_IsRejected()
{
// A zero TTL makes every Deployer/Administrator circuit's poll a cache miss,
// so the whole fleet is re-flattened on each one — the exact cost the cache
// exists to avoid.
var result = Validate(new DeploymentManagerOptions { PendingUpdatesCacheTtl = TimeSpan.Zero });
Assert.True(result.Failed);
Assert.Contains("PendingUpdatesCacheTtl", result.FailureMessage);
}
[Fact]
public void NegativePendingUpdatesCacheTtl_IsRejected()
{
var result = Validate(new DeploymentManagerOptions
{
PendingUpdatesCacheTtl = TimeSpan.FromSeconds(-1)
});
Assert.True(result.Failed);
Assert.Contains("PendingUpdatesCacheTtl", result.FailureMessage);
}
}