diff --git a/docs/GatewayConfiguration.md b/docs/GatewayConfiguration.md index b499fca7..eb143a48 100644 --- a/docs/GatewayConfiguration.md +++ b/docs/GatewayConfiguration.md @@ -24,8 +24,10 @@ paths, timeouts, queue sizes, enum values, or protocol values are invalid. "StartupTimeoutSeconds": 30, "PipeConnectAttemptTimeoutMilliseconds": 2000, "ShutdownTimeoutSeconds": 10, - "HeartbeatIntervalSeconds": 5, + "HeartbeatCheckIntervalSeconds": 5, "HeartbeatGraceSeconds": 15, + "HeartbeatStuckCeilingSeconds": 75, + "EventChannelFullModeTimeoutMilliseconds": 5000, "MaxMessageBytes": 16842752 }, "Sessions": { @@ -145,8 +147,11 @@ launch CWD (SEC-01, SEC-33). | `MxGateway:Worker:WriteCompletionWaitMilliseconds` | `1500` | Bounded wait the worker holds a unary write reply (`Write`/`Write2`/`WriteSecured`/`WriteSecured2`; bulk writes excluded) for the matching MXAccess `OnWriteComplete` callback, so the reply's `statuses` carry the real commit outcome. `0` disables the wait (pure fire-and-forget replies). Must be `>= 0`. The gateway conveys the value to the worker via the `MXGATEWAY_WORKER_WRITE_COMPLETION_WAIT_MS` environment variable. Consumers that time their own writes must budget above this wait: OtOpcUa's GalaxyDriver wraps gateway writes in a 2 s Tier A resilience timeout, so a deployment raising this option past ~2000 must raise that driver `ResilienceConfig` write timeout in step or slow-but-successful commits surface as consumer-side failures. | | `MxGateway:Worker:EventQueueCapacity` | `10000` | Capacity, in events, of the worker's outbound MXAccess event queue. Must be between `1000` and `1000000`. This is burst headroom, not a throttle: the queue has no drop policy, so filling it records a `QueueOverflow` worker fault and faults the session. Raise it for sessions whose subscription set can outrun the drain loop (large advise sets, slow event consumers); the backing queue pre-allocates its slots, so the ceiling keeps a mistyped value from committing the 32-bit worker to an outsized allocation. The gateway conveys the value to the worker via the `MXGATEWAY_EVENT_QUEUE_CAPACITY` environment variable; a missing or unusable value leaves the worker on the 10000 default rather than failing the session. | | `MxGateway:Worker:ShutdownTimeoutSeconds` | `10` | Grace period for worker shutdown before the gateway treats shutdown as failed and may kill the worker process tree. | -| `MxGateway:Worker:HeartbeatIntervalSeconds` | `5` | Worker heartbeat send interval and gateway heartbeat check cadence input. | -| `MxGateway:Worker:HeartbeatGraceSeconds` | `15` | Maximum age of the last worker heartbeat before the gateway faults the worker. This must be greater than or equal to `HeartbeatIntervalSeconds`. | +| `MxGateway:Worker:HeartbeatCheckIntervalSeconds` | `5` | How often the gateway checks the age of the worker's last heartbeat against `HeartbeatGraceSeconds`. This is the gateway-side check cadence only; the worker sends heartbeats on its own fixed 5-second interval, which no gateway option reaches. Must be greater than zero. | +| `MxGateway:Worker:HeartbeatIntervalSeconds` | *(unset)* | **Deprecated** alias of `HeartbeatCheckIntervalSeconds` (mxaccessgw#192). The old name implied the worker's send interval, but the value only ever set the gateway's check cadence, which is what it still sets. Setting both keys fails validation. | +| `MxGateway:Worker:HeartbeatGraceSeconds` | `15` | Maximum age of the last worker heartbeat before the gateway faults the worker. This must be greater than or equal to `HeartbeatCheckIntervalSeconds`. | +| `MxGateway:Worker:HeartbeatStuckCeilingSeconds` | `75` | Ceiling on the gateway's in-flight-command heartbeat skip. While a command is pending the gateway tolerates a stale heartbeat, because the worker STA is busy inside a COM call; once the oldest pending command is older than this, the watchdog faults the worker anyway so a truly stuck COM call cannot hide a dead worker. Must be greater than or equal to `HeartbeatGraceSeconds`. The worker's own watchdog keeps its separate, fixed 75-second ceiling. | +| `MxGateway:Worker:EventChannelFullModeTimeoutMilliseconds` | `5000` | How long the gateway waits for a session's bounded event channel (`MxGateway:Events:QueueCapacity`) to accept a worker event before faulting the session with `QueueOverflow`. A consumer stalled for longer than this is treated as stuck rather than slow. Must be greater than zero. | | `MxGateway:Worker:MaxMessageBytes` | `16842752` | Maximum worker IPC frame payload size in bytes. The validator allows values from `1024` through `268435456`, and additionally requires this to be at least `MxGateway:Protocol:MaxGrpcMessageBytes` plus a 65536-byte (64 KiB) envelope-overhead reserve **and at most that cap plus twice the reserve**. The default is the 16 MiB public gRPC cap plus one reserve. The gateway conveys the negotiated value to the worker in the handshake (`GatewayHello.max_frame_bytes`), so the worker frames to the same limit rather than a hard-coded default. The band is narrow by design, so changing either message-size knob alone no longer validates — move `MxGateway:Protocol:MaxGrpcMessageBytes` and this one together, keeping this one one to two reserves above it. | `PipeConnectAttemptTimeoutMilliseconds`, timeout values, heartbeat values, and diff --git a/docs/GatewayProcessDesign.md b/docs/GatewayProcessDesign.md index d8dc4f28..4e64f358 100644 --- a/docs/GatewayProcessDesign.md +++ b/docs/GatewayProcessDesign.md @@ -945,7 +945,7 @@ Suggested configuration shape: "StartupTimeoutSeconds": 30, "PipeConnectAttemptTimeoutMilliseconds": 2000, "ShutdownTimeoutSeconds": 10, - "HeartbeatIntervalSeconds": 5, + "HeartbeatCheckIntervalSeconds": 5, "HeartbeatGraceSeconds": 15, "MaxMessageBytes": 16777216 }, diff --git a/docs/MxAccessWorkerInstanceDesign.md b/docs/MxAccessWorkerInstanceDesign.md index 42d79632..e3785fb5 100644 --- a/docs/MxAccessWorkerInstanceDesign.md +++ b/docs/MxAccessWorkerInstanceDesign.md @@ -898,8 +898,10 @@ frame maximum cannot be delivered to the client at all. `WorkerPipeSession` starts the heartbeat loop after the gateway validates `WorkerHello` and receives `WorkerReady`. Heartbeats continue until `WorkerShutdown`, cancellation, or a pipe/protocol failure stops the session. -The loop uses `WorkerPipeSessionOptions.HeartbeatInterval`; the default matches -the gateway worker heartbeat interval. +The loop uses `WorkerPipeSessionOptions.HeartbeatInterval` (default 5 s). The +gateway does not configure it: `MxGateway:Worker:HeartbeatCheckIntervalSeconds` +sets only how often the gateway checks heartbeat age, and +`MxGateway:Worker:HeartbeatGraceSeconds` how stale a heartbeat may get. The worker heartbeat proves that: diff --git a/src/ZB.MOM.WW.MxGateway.IntegrationTests/WorkerLiveMxAccessSmokeTests.cs b/src/ZB.MOM.WW.MxGateway.IntegrationTests/WorkerLiveMxAccessSmokeTests.cs index 04bbdaaa..0c06d60d 100644 --- a/src/ZB.MOM.WW.MxGateway.IntegrationTests/WorkerLiveMxAccessSmokeTests.cs +++ b/src/ZB.MOM.WW.MxGateway.IntegrationTests/WorkerLiveMxAccessSmokeTests.cs @@ -1883,7 +1883,7 @@ public sealed class WorkerLiveMxAccessSmokeTests(ITestOutputHelper output) ExecutablePath = workerExecutablePath, StartupTimeoutSeconds = 30, ShutdownTimeoutSeconds = 15, - HeartbeatIntervalSeconds = 5, + HeartbeatCheckIntervalSeconds = 5, HeartbeatGraceSeconds = 15, MaxMessageBytes = WorkerFrameProtocolOptions.DefaultMaxMessageBytes, RequiredArchitecture = WorkerArchitecture.X86, diff --git a/src/ZB.MOM.WW.MxGateway.Server/Configuration/EffectiveWorkerConfiguration.cs b/src/ZB.MOM.WW.MxGateway.Server/Configuration/EffectiveWorkerConfiguration.cs index 738be771..5f7c75bd 100644 --- a/src/ZB.MOM.WW.MxGateway.Server/Configuration/EffectiveWorkerConfiguration.cs +++ b/src/ZB.MOM.WW.MxGateway.Server/Configuration/EffectiveWorkerConfiguration.cs @@ -6,6 +6,8 @@ public sealed record EffectiveWorkerConfiguration( string RequiredArchitecture, int StartupTimeoutSeconds, int ShutdownTimeoutSeconds, - int HeartbeatIntervalSeconds, + int HeartbeatCheckIntervalSeconds, int HeartbeatGraceSeconds, + int HeartbeatStuckCeilingSeconds, + int EventChannelFullModeTimeoutMilliseconds, int MaxMessageBytes); diff --git a/src/ZB.MOM.WW.MxGateway.Server/Configuration/GatewayConfigurationProvider.cs b/src/ZB.MOM.WW.MxGateway.Server/Configuration/GatewayConfigurationProvider.cs index b134c372..e49c6021 100644 --- a/src/ZB.MOM.WW.MxGateway.Server/Configuration/GatewayConfigurationProvider.cs +++ b/src/ZB.MOM.WW.MxGateway.Server/Configuration/GatewayConfigurationProvider.cs @@ -38,8 +38,10 @@ public sealed class GatewayConfigurationProvider(IOptions option RequiredArchitecture: value.Worker.RequiredArchitecture.ToString(), StartupTimeoutSeconds: value.Worker.StartupTimeoutSeconds, ShutdownTimeoutSeconds: value.Worker.ShutdownTimeoutSeconds, - HeartbeatIntervalSeconds: value.Worker.HeartbeatIntervalSeconds, + HeartbeatCheckIntervalSeconds: value.Worker.ResolveHeartbeatCheckIntervalSeconds(), HeartbeatGraceSeconds: value.Worker.HeartbeatGraceSeconds, + HeartbeatStuckCeilingSeconds: value.Worker.HeartbeatStuckCeilingSeconds, + EventChannelFullModeTimeoutMilliseconds: value.Worker.EventChannelFullModeTimeoutMilliseconds, MaxMessageBytes: value.Worker.MaxMessageBytes), Sessions: new EffectiveSessionConfiguration( DefaultCommandTimeoutSeconds: value.Sessions.DefaultCommandTimeoutSeconds, diff --git a/src/ZB.MOM.WW.MxGateway.Server/Configuration/GatewayOptionsValidator.cs b/src/ZB.MOM.WW.MxGateway.Server/Configuration/GatewayOptionsValidator.cs index 9e5d5f39..7a4a56a2 100644 --- a/src/ZB.MOM.WW.MxGateway.Server/Configuration/GatewayOptionsValidator.cs +++ b/src/ZB.MOM.WW.MxGateway.Server/Configuration/GatewayOptionsValidator.cs @@ -258,19 +258,37 @@ public sealed class GatewayOptionsValidator : OptionsValidatorBase MaximumWorkerEventQueueCapacity) diff --git a/src/ZB.MOM.WW.MxGateway.Server/Configuration/WorkerOptions.cs b/src/ZB.MOM.WW.MxGateway.Server/Configuration/WorkerOptions.cs index b3f64fac..3e619b00 100644 --- a/src/ZB.MOM.WW.MxGateway.Server/Configuration/WorkerOptions.cs +++ b/src/ZB.MOM.WW.MxGateway.Server/Configuration/WorkerOptions.cs @@ -42,12 +42,59 @@ public sealed class WorkerOptions /// The maximum time in seconds for graceful shutdown. public int ShutdownTimeoutSeconds { get; init; } = 10; - /// The interval in seconds for worker heartbeats. - public int HeartbeatIntervalSeconds { get; init; } = 5; + /// Default for . + public const int DefaultHeartbeatCheckIntervalSeconds = 5; + + /// + /// How often, in seconds, the gateway checks the age of the worker's last heartbeat + /// against . This is the gateway-side check + /// cadence only: the worker sends heartbeats on its own fixed 5-second interval, which + /// this option does not reach. falls back to the deprecated + /// key, then to + /// ; read the resolved value through + /// . + /// + public int? HeartbeatCheckIntervalSeconds { get; init; } + + /// + /// Deprecated alias of (mxaccessgw#192). The + /// name implied the worker's heartbeat send interval, but the value only ever + /// drove the gateway's check cadence. Still honoured so existing configuration keeps + /// its meaning; setting both keys is a validation error. + /// + public int? HeartbeatIntervalSeconds { get; init; } /// The grace period in seconds after a heartbeat before considering the worker unresponsive. public int HeartbeatGraceSeconds { get; init; } = 15; + /// + /// How long, in milliseconds, the gateway waits for its bounded per-session event + /// channel to accept a worker event before faulting the session with a + /// QueueOverflow. A consumer that stalls for longer than this is treated as stuck. + /// Default 5000; must be greater than zero. + /// + public int EventChannelFullModeTimeoutMilliseconds { get; init; } = + (int)Workers.WorkerClientOptions.DefaultEventChannelFullModeTimeout.TotalMilliseconds; + + /// + /// Ceiling, in seconds, on the gateway's in-flight-command heartbeat skip: while a command + /// is pending the gateway tolerates a stale heartbeat (the worker STA is busy in a COM + /// call), but once the oldest pending command is older than this the heartbeat watchdog + /// faults the worker anyway. Default 75; must be at least . + /// The worker's own watchdog keeps its separate, fixed 75-second ceiling. + /// + public int HeartbeatStuckCeilingSeconds { get; init; } = + (int)Workers.WorkerClientOptions.DefaultHeartbeatStuckCeiling.TotalSeconds; + + /// + /// Resolves the effective heartbeat check interval: , + /// else the deprecated , else + /// . + /// + /// The heartbeat check interval in seconds. + public int ResolveHeartbeatCheckIntervalSeconds() => + HeartbeatCheckIntervalSeconds ?? HeartbeatIntervalSeconds ?? DefaultHeartbeatCheckIntervalSeconds; + /// /// The maximum worker-frame (pipe) message size in bytes. Must stay at least /// above diff --git a/src/ZB.MOM.WW.MxGateway.Server/Sessions/SessionWorkerClientFactory.cs b/src/ZB.MOM.WW.MxGateway.Server/Sessions/SessionWorkerClientFactory.cs index 7e7401f1..072fa5ee 100644 --- a/src/ZB.MOM.WW.MxGateway.Server/Sessions/SessionWorkerClientFactory.cs +++ b/src/ZB.MOM.WW.MxGateway.Server/Sessions/SessionWorkerClientFactory.cs @@ -92,13 +92,7 @@ public sealed class SessionWorkerClientFactory : ISessionWorkerClientFactory pipe, frameOptions, processHandle); - WorkerClientOptions clientOptions = new() - { - HeartbeatGrace = TimeSpan.FromSeconds(_options.Worker.HeartbeatGraceSeconds), - HeartbeatCheckInterval = TimeSpan.FromSeconds(_options.Worker.HeartbeatIntervalSeconds), - EventChannelCapacity = _options.Events.QueueCapacity, - MaxPendingCommands = _options.Sessions.MaxPendingCommandsPerSession, - }; + WorkerClientOptions clientOptions = CreateWorkerClientOptions(_options); workerClient = new WorkerClient( connection, @@ -208,4 +202,26 @@ public sealed class SessionWorkerClientFactory : ISessionWorkerClientFactory { await pipe.WaitForConnectionAsync(cancellationToken).ConfigureAwait(false); } + + /// + /// Maps the bound MxGateway:* options onto the per-session . + /// Every field is set from configuration here, so none is left + /// silently on its compile-time default. + /// + /// The bound gateway options. + /// The worker client options for a new session. + internal static WorkerClientOptions CreateWorkerClientOptions(GatewayOptions options) + { + ArgumentNullException.ThrowIfNull(options); + + return new WorkerClientOptions + { + HeartbeatGrace = TimeSpan.FromSeconds(options.Worker.HeartbeatGraceSeconds), + HeartbeatCheckInterval = TimeSpan.FromSeconds(options.Worker.ResolveHeartbeatCheckIntervalSeconds()), + HeartbeatStuckCeiling = TimeSpan.FromSeconds(options.Worker.HeartbeatStuckCeilingSeconds), + EventChannelCapacity = options.Events.QueueCapacity, + EventChannelFullModeTimeout = TimeSpan.FromMilliseconds(options.Worker.EventChannelFullModeTimeoutMilliseconds), + MaxPendingCommands = options.Sessions.MaxPendingCommandsPerSession, + }; + } } diff --git a/src/ZB.MOM.WW.MxGateway.Server/appsettings.json b/src/ZB.MOM.WW.MxGateway.Server/appsettings.json index 5eabc8b4..92a5a34c 100644 --- a/src/ZB.MOM.WW.MxGateway.Server/appsettings.json +++ b/src/ZB.MOM.WW.MxGateway.Server/appsettings.json @@ -49,8 +49,10 @@ "RequiredArchitecture": "X86", "StartupTimeoutSeconds": 30, "ShutdownTimeoutSeconds": 10, - "HeartbeatIntervalSeconds": 5, + "HeartbeatCheckIntervalSeconds": 5, "HeartbeatGraceSeconds": 15, + "HeartbeatStuckCeilingSeconds": 75, + "EventChannelFullModeTimeoutMilliseconds": 5000, "MaxMessageBytes": 16842752 }, "Sessions": { diff --git a/src/ZB.MOM.WW.MxGateway.Tests/Configuration/GatewayOptionsTests.cs b/src/ZB.MOM.WW.MxGateway.Tests/Configuration/GatewayOptionsTests.cs index 889be21a..dcbfa49a 100644 --- a/src/ZB.MOM.WW.MxGateway.Tests/Configuration/GatewayOptionsTests.cs +++ b/src/ZB.MOM.WW.MxGateway.Tests/Configuration/GatewayOptionsTests.cs @@ -41,7 +41,9 @@ public sealed class GatewayOptionsTests Assert.Equal(2000, options.Worker.PipeConnectAttemptTimeoutMilliseconds); Assert.Equal(1500, options.Worker.WriteCompletionWaitMilliseconds); Assert.Equal(10, options.Worker.ShutdownTimeoutSeconds); - Assert.Equal(5, options.Worker.HeartbeatIntervalSeconds); + Assert.Equal(5, options.Worker.ResolveHeartbeatCheckIntervalSeconds()); + Assert.Equal(75, options.Worker.HeartbeatStuckCeilingSeconds); + Assert.Equal(5000, options.Worker.EventChannelFullModeTimeoutMilliseconds); Assert.Equal(15, options.Worker.HeartbeatGraceSeconds); // 16 MiB public gRPC cap plus the 64 KiB worker-frame envelope reserve for headroom. Assert.Equal((16 * 1024 * 1024) + (64 * 1024), options.Worker.MaxMessageBytes); @@ -110,6 +112,11 @@ public sealed class GatewayOptionsTests [InlineData("MxGateway:Worker:ExecutablePath", "worker.dll", "MxGateway:Worker:ExecutablePath must point to a .exe file.")] [InlineData("MxGateway:Worker:PipeConnectAttemptTimeoutMilliseconds", "0", "MxGateway:Worker:PipeConnectAttemptTimeoutMilliseconds must be greater than zero.")] [InlineData("MxGateway:Worker:WriteCompletionWaitMilliseconds", "-1", "MxGateway:Worker:WriteCompletionWaitMilliseconds must be greater than or equal to zero.")] + [InlineData("MxGateway:Worker:HeartbeatCheckIntervalSeconds", "0", "MxGateway:Worker:HeartbeatCheckIntervalSeconds must be greater than zero.")] + [InlineData("MxGateway:Worker:HeartbeatIntervalSeconds", "0", "MxGateway:Worker:HeartbeatCheckIntervalSeconds must be greater than zero.")] + [InlineData("MxGateway:Worker:HeartbeatCheckIntervalSeconds", "16", "MxGateway:Worker:HeartbeatGraceSeconds must be greater than or equal to HeartbeatCheckIntervalSeconds.")] + [InlineData("MxGateway:Worker:EventChannelFullModeTimeoutMilliseconds", "0", "MxGateway:Worker:EventChannelFullModeTimeoutMilliseconds must be greater than zero.")] + [InlineData("MxGateway:Worker:HeartbeatStuckCeilingSeconds", "14", "MxGateway:Worker:HeartbeatStuckCeilingSeconds must be greater than or equal to HeartbeatGraceSeconds.")] [InlineData("MxGateway:Sessions:DefaultLeaseSeconds", "0", "MxGateway:Sessions:DefaultLeaseSeconds must be greater than zero.")] [InlineData("MxGateway:Sessions:LeaseSweepIntervalSeconds", "0", "MxGateway:Sessions:LeaseSweepIntervalSeconds must be greater than zero.")] [InlineData("MxGateway:Sessions:DetachGraceSeconds", "-1", "MxGateway:Sessions:DetachGraceSeconds must be zero or greater (0 disables detach-grace retention).")] @@ -126,6 +133,42 @@ public sealed class GatewayOptionsTests Assert.Contains(exception.Failures, failure => failure.Contains(expectedFailure, StringComparison.Ordinal)); } + /// + /// mxaccessgw#192: the deprecated HeartbeatIntervalSeconds key still sets the + /// heartbeat check interval, so existing configuration keeps its meaning after the rename. + /// + [Fact] + public void HeartbeatIntervalSeconds_DeprecatedAlias_SetsCheckInterval() + { + GatewayOptions options = BindOptions(new Dictionary + { + ["MxGateway:Ldap:ServiceAccountPassword"] = "test-bind-password", + ["MxGateway:Worker:HeartbeatIntervalSeconds"] = "7", + }); + + Assert.Equal(7, options.Worker.ResolveHeartbeatCheckIntervalSeconds()); + } + + /// + /// mxaccessgw#192: setting both the new key and its deprecated alias is ambiguous and + /// fails validation rather than silently preferring one. + /// + [Fact] + public void HeartbeatCheckInterval_BothKeysSet_FailsValidation() + { + OptionsValidationException exception = Assert.Throws(() => + _ = BindOptions(new Dictionary + { + ["MxGateway:Ldap:ServiceAccountPassword"] = "test-bind-password", + ["MxGateway:Worker:HeartbeatCheckIntervalSeconds"] = "5", + ["MxGateway:Worker:HeartbeatIntervalSeconds"] = "5", + })); + + Assert.Contains( + exception.Failures, + failure => failure.Contains("HeartbeatIntervalSeconds is a deprecated alias", StringComparison.Ordinal)); + } + /// Verifies that pepper secret names are redacted in the effective configuration. [Fact] public void EffectiveConfiguration_RedactsPepperSecretName() diff --git a/src/ZB.MOM.WW.MxGateway.Tests/Gateway/GatewayEndToEndFakeWorkerSmokeTests.cs b/src/ZB.MOM.WW.MxGateway.Tests/Gateway/GatewayEndToEndFakeWorkerSmokeTests.cs index d9aec6ed..48e76f2b 100644 --- a/src/ZB.MOM.WW.MxGateway.Tests/Gateway/GatewayEndToEndFakeWorkerSmokeTests.cs +++ b/src/ZB.MOM.WW.MxGateway.Tests/Gateway/GatewayEndToEndFakeWorkerSmokeTests.cs @@ -317,7 +317,7 @@ public sealed class GatewayEndToEndFakeWorkerSmokeTests { StartupTimeoutSeconds = 5, ShutdownTimeoutSeconds = 5, - HeartbeatIntervalSeconds = 30, + HeartbeatCheckIntervalSeconds = 30, HeartbeatGraceSeconds = 30, MaxMessageBytes = WorkerFrameProtocolOptions.DefaultMaxMessageBytes, }, diff --git a/src/ZB.MOM.WW.MxGateway.Tests/Gateway/GatewayEndToEndMultiSubscriberTests.cs b/src/ZB.MOM.WW.MxGateway.Tests/Gateway/GatewayEndToEndMultiSubscriberTests.cs index f50c081a..1b5791b8 100644 --- a/src/ZB.MOM.WW.MxGateway.Tests/Gateway/GatewayEndToEndMultiSubscriberTests.cs +++ b/src/ZB.MOM.WW.MxGateway.Tests/Gateway/GatewayEndToEndMultiSubscriberTests.cs @@ -528,7 +528,7 @@ public sealed class GatewayEndToEndMultiSubscriberTests(ITestOutputHelper output { StartupTimeoutSeconds = 5, ShutdownTimeoutSeconds = 5, - HeartbeatIntervalSeconds = 30, + HeartbeatCheckIntervalSeconds = 30, HeartbeatGraceSeconds = 30, MaxMessageBytes = WorkerFrameProtocolOptions.DefaultMaxMessageBytes, }, diff --git a/src/ZB.MOM.WW.MxGateway.Tests/Gateway/GatewayEndToEndReconnectReplayTests.cs b/src/ZB.MOM.WW.MxGateway.Tests/Gateway/GatewayEndToEndReconnectReplayTests.cs index fd61cb94..6380cc9a 100644 --- a/src/ZB.MOM.WW.MxGateway.Tests/Gateway/GatewayEndToEndReconnectReplayTests.cs +++ b/src/ZB.MOM.WW.MxGateway.Tests/Gateway/GatewayEndToEndReconnectReplayTests.cs @@ -644,7 +644,7 @@ public sealed class GatewayEndToEndReconnectReplayTests(ITestOutputHelper output { StartupTimeoutSeconds = 5, ShutdownTimeoutSeconds = 5, - HeartbeatIntervalSeconds = 30, + HeartbeatCheckIntervalSeconds = 30, HeartbeatGraceSeconds = 30, MaxMessageBytes = WorkerFrameProtocolOptions.DefaultMaxMessageBytes, }, diff --git a/src/ZB.MOM.WW.MxGateway.Tests/Gateway/Sessions/SessionWorkerClientFactoryFakeWorkerTests.cs b/src/ZB.MOM.WW.MxGateway.Tests/Gateway/Sessions/SessionWorkerClientFactoryFakeWorkerTests.cs index 3dd5ea2b..3ec73b96 100644 --- a/src/ZB.MOM.WW.MxGateway.Tests/Gateway/Sessions/SessionWorkerClientFactoryFakeWorkerTests.cs +++ b/src/ZB.MOM.WW.MxGateway.Tests/Gateway/Sessions/SessionWorkerClientFactoryFakeWorkerTests.cs @@ -124,6 +124,52 @@ public sealed class SessionWorkerClientFactoryFakeWorkerTests : IAsyncLifetime Assert.True(launcher.Process.IsDisposed); } + /// + /// mxaccessgw#192: every field comes from configuration. + /// The heartbeat check interval binds from HeartbeatCheckIntervalSeconds (not the + /// worker send cadence), and the event-channel full-mode timeout and heartbeat stuck + /// ceiling — previously fixed compile-time defaults — follow their new options. + /// + [Fact] + public void CreateWorkerClientOptions_MapsEveryFieldFromConfiguration() + { + GatewayOptions options = new() + { + Worker = new WorkerOptions + { + HeartbeatCheckIntervalSeconds = 3, + HeartbeatGraceSeconds = 20, + HeartbeatStuckCeilingSeconds = 90, + EventChannelFullModeTimeoutMilliseconds = 2500, + }, + Events = new EventOptions { QueueCapacity = 64 }, + Sessions = new SessionOptions { MaxPendingCommandsPerSession = 32 }, + }; + + WorkerClientOptions clientOptions = SessionWorkerClientFactory.CreateWorkerClientOptions(options); + + Assert.Equal(TimeSpan.FromSeconds(3), clientOptions.HeartbeatCheckInterval); + Assert.Equal(TimeSpan.FromSeconds(20), clientOptions.HeartbeatGrace); + Assert.Equal(TimeSpan.FromSeconds(90), clientOptions.HeartbeatStuckCeiling); + Assert.Equal(TimeSpan.FromMilliseconds(2500), clientOptions.EventChannelFullModeTimeout); + Assert.Equal(64, clientOptions.EventChannelCapacity); + Assert.Equal(32, clientOptions.MaxPendingCommands); + } + + /// + /// mxaccessgw#192: with no worker options set, the mapped values equal the historical + /// compile-time defaults, so the change is behaviour-neutral for existing deployments. + /// + [Fact] + public void CreateWorkerClientOptions_Defaults_MatchHistoricalConstants() + { + WorkerClientOptions clientOptions = SessionWorkerClientFactory.CreateWorkerClientOptions(new GatewayOptions()); + + Assert.Equal(TimeSpan.FromSeconds(5), clientOptions.HeartbeatCheckInterval); + Assert.Equal(WorkerClientOptions.DefaultHeartbeatStuckCeiling, clientOptions.HeartbeatStuckCeiling); + Assert.Equal(WorkerClientOptions.DefaultEventChannelFullModeTimeout, clientOptions.EventChannelFullModeTimeout); + } + private static GatewayOptions CreateOptions(int startupTimeoutSeconds = 5) { return new GatewayOptions @@ -132,7 +178,7 @@ public sealed class SessionWorkerClientFactoryFakeWorkerTests : IAsyncLifetime { StartupTimeoutSeconds = startupTimeoutSeconds, ShutdownTimeoutSeconds = 5, - HeartbeatIntervalSeconds = 30, + HeartbeatCheckIntervalSeconds = 30, HeartbeatGraceSeconds = 30, MaxMessageBytes = WorkerFrameProtocolOptions.DefaultMaxMessageBytes, },