41a5ecf14a
An external system's MaxRetries/RetryDelay existed on the central entity but never reached a site and had no management surface, so every ExternalSystem.CachedCall buffered with the S&F engine default (DefaultMaxRetries 50 x DefaultRetryInterval 30s ~= 25 min to park) whatever central had configured. The sibling DatabaseConnectionArtifact had always carried its equivalents. The consumption end was already wired: ExternalSystemClient.CachedCallAsync already read system.MaxRetries/RetryDelay and passed them to EnqueueAsync with the 0-as-unset convention. Only the transport and persistence were missing. Commons - ExternalSystemArtifact gains MaxRetries/RetryDelay as optional positional params (0 / TimeSpan.Zero = unset), matching DatabaseConnectionArtifact rather than going nullable, so it maps 1:1 onto the entity and the proto3 scalars. - Create/UpdateExternalSystemCommand gain nullable MaxRetries/RetryDelay, following the existing TimeoutSeconds "omit to preserve" convention. Both additive. Central - ManagementActor create maps both; update preserves-if-null. - ArtifactDeploymentService projects them onto the artifact. Wire - site_command.proto ExternalSystemArtifactDto gains max_retries=7 / retry_delay=8 (google.protobuf.Duration), mirroring DatabaseConnectionArtifactDto. Additive: a pre-existing site decodes them as 0/absent, which IS the unset value, so old behaviour is preserved. Vendored C# regenerated via docker/regen-proto.sh sitecommand; csproj Protobuf item re-commented, no message types added or removed. Site - external_systems gains max_retries / retry_delay_ms via AddColumnIfMissing, DEFAULT 0 = unset. Storage upsert, repository SELECT/mapping (new ordinals 6/7 appended so existing ones are untouched), apply path, and the legacy migrator's explicit column list all carry them. Replicated-table decision: external_systems IS in SiteLocalDbSetup.ReplicatedTables, so this was checked against the AckTime/native_alarm_state precedent. Real columns are correct here, not a JSON bag: the table has no general-purpose config column (auth_configuration and method_definitions are both semantically specific), timeout_seconds already set the additive-column precedent on this exact table, and sibling database_connections stores the same two values as plain columns. Verified in LocalDb source that RegisterReplicated re-reads PRAGMA table_info every boot and its install script is DROP-then-CREATE, so capture triggers rebuild over the new column set automatically, and SiteStorageSchema.Apply runs before registration on the same boot. The only cost is the ReplicatedTable.ComputeDigest change, which the sync handshake compares fail-closed - a mixed-version pair refuses to sync loudly instead of diverging silently. Both-nodes-together is already the standing site-pair rule, so no new operational constraint; recorded in topology-guide.md. Also fixed: ArtifactDiff.CompareExternalSystem never compared MaxRetries/RetryDelay, so a bundle import that changed a system's retry budget previewed as "Identical" - harmless while the values were inert, a live behaviour change now. No EF migration: the central ExternalSystemDefinitions columns already exist (InitialSchema). Central UI already had both form fields. Tests: site storage round-trip + unset-default, site apply path, central artifact projection, proto round-trip (via the shared sample), management create/preserve, CLI option parse + alias, and diff reporting. Fail-before verified on the two core tests (expected 7 got 0 on the read path; expected 9 got 0 on the apply path). Docs: Component-ExternalSystemGateway, Component-StoreAndForward, Component-CLI, components/StoreAndForward, components/SiteRuntime, deployment/topology-guide, CLI README (which was also missing --timeout-seconds entirely).
103 lines
3.7 KiB
C#
103 lines
3.7 KiB
C#
using System.CommandLine;
|
|
using ZB.MOM.WW.ScadaBridge.CLI.Commands;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.CLI.Tests.Commands;
|
|
|
|
/// <summary>
|
|
/// Deferred-work row 27(b): <c>external-system create</c> and <c>external-system update</c>
|
|
/// must expose the per-system Store-and-Forward retry policy. Before this the fields existed
|
|
/// on the central entity but had NO management surface at all — the only way to set them was
|
|
/// a direct DB edit of <c>ExternalSystemDefinitions</c>.
|
|
/// <para>
|
|
/// The delay flag is named <c>--retry-delay-seconds</c> to match the sibling
|
|
/// <c>--timeout-seconds</c> on these same commands (the repo-wide CLI convention is an explicit
|
|
/// unit suffix), with <c>--retry-delay</c> kept as an alias.
|
|
/// </para>
|
|
/// </summary>
|
|
public class ExternalSystemRetryOptionTests
|
|
{
|
|
private static readonly Option<string> Url = new("--url") { Recursive = true };
|
|
private static readonly Option<string> Format = new("--format") { Recursive = true };
|
|
private static readonly Option<string> Username = new("--username") { Recursive = true };
|
|
private static readonly Option<string> Password = new("--password") { Recursive = true };
|
|
|
|
private static Command Group() => ExternalSystemCommands.Build(Url, Format, Username, Password);
|
|
|
|
private static Option? FindOption(Command command, string name)
|
|
=> command.Options.SingleOrDefault(o => o.Name == name);
|
|
|
|
[Theory]
|
|
[InlineData("create")]
|
|
[InlineData("update")]
|
|
public void HasOptionalRetryPolicyOptions(string subcommand)
|
|
{
|
|
var cmd = Group().Subcommands.Single(c => c.Name == subcommand);
|
|
|
|
var maxRetries = FindOption(cmd, "--max-retries");
|
|
Assert.NotNull(maxRetries);
|
|
Assert.False(maxRetries!.Required);
|
|
|
|
var retryDelay = FindOption(cmd, "--retry-delay-seconds");
|
|
Assert.NotNull(retryDelay);
|
|
Assert.False(retryDelay!.Required);
|
|
}
|
|
|
|
[Fact]
|
|
public void Create_ParsesRetryPolicyValues()
|
|
{
|
|
var parse = Group().Parse(new[]
|
|
{
|
|
"create", "--name", "Sys", "--endpoint-url", "http://x", "--auth-type", "none",
|
|
"--max-retries", "8", "--retry-delay-seconds", "60",
|
|
});
|
|
|
|
Assert.Empty(parse.Errors);
|
|
Assert.Equal(8, parse.GetValue<int?>("--max-retries"));
|
|
Assert.Equal(60, parse.GetValue<int?>("--retry-delay-seconds"));
|
|
}
|
|
|
|
[Fact]
|
|
public void Update_ParsesRetryPolicyValues()
|
|
{
|
|
var parse = Group().Parse(new[]
|
|
{
|
|
"update", "--id", "7", "--name", "Sys", "--endpoint-url", "http://x",
|
|
"--auth-type", "none", "--max-retries", "3", "--retry-delay-seconds", "10",
|
|
});
|
|
|
|
Assert.Empty(parse.Errors);
|
|
Assert.Equal(3, parse.GetValue<int?>("--max-retries"));
|
|
Assert.Equal(10, parse.GetValue<int?>("--retry-delay-seconds"));
|
|
}
|
|
|
|
[Fact]
|
|
public void RetryDelayAliasIsAccepted()
|
|
{
|
|
var parse = Group().Parse(new[]
|
|
{
|
|
"create", "--name", "Sys", "--endpoint-url", "http://x", "--auth-type", "none",
|
|
"--retry-delay", "45",
|
|
});
|
|
|
|
Assert.Empty(parse.Errors);
|
|
Assert.Equal(45, parse.GetValue<int?>("--retry-delay-seconds"));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Omission must stay distinguishable from an explicit 0 — that is what makes update's
|
|
/// "omit to preserve" rule and create's "fall back to the engine default" rule work.
|
|
/// </summary>
|
|
[Fact]
|
|
public void OmittedRetryPolicy_ParsesAsNull()
|
|
{
|
|
var parse = Group().Parse(new[]
|
|
{
|
|
"create", "--name", "Sys", "--endpoint-url", "http://x", "--auth-type", "none",
|
|
});
|
|
|
|
Assert.Empty(parse.Errors);
|
|
Assert.Null(parse.GetValue<int?>("--max-retries"));
|
|
Assert.Null(parse.GetValue<int?>("--retry-delay-seconds"));
|
|
}
|
|
}
|