fix(gateway): split the heartbeat check interval from the send interval; expose the two fixed worker-client timeouts (mxaccessgw#192)
R21-O14: MxGateway:Worker:HeartbeatIntervalSeconds was documented as the worker heartbeat send interval, but it never reached the worker (which sends on its own fixed 5 s) and only set the gateway's HeartbeatCheckInterval. It is renamed HeartbeatCheckIntervalSeconds (default 5, unchanged). The old key stays as a deprecated alias with the same meaning so existing appsettings keep working; setting both is a validation error. The grace-vs-interval check now compares against the resolved check interval. R21-O15: WorkerClientOptions.EventChannelFullModeTimeout and HeartbeatStuckCeiling were always their compile-time defaults. They are now MxGateway:Worker:EventChannelFullModeTimeoutMilliseconds (default 5000, > 0) and HeartbeatStuckCeilingSeconds (default 75, >= HeartbeatGraceSeconds). The factory's mapping moved into SessionWorkerClientFactory.CreateWorkerClientOptions so every field is set from configuration and is testable. The effective-config record shows the resolved check interval and both new values. Docs: GatewayConfiguration.md, GatewayProcessDesign.md sample, MxAccessWorkerInstanceDesign.md heartbeat section; appsettings.json uses the new keys. Tests: CreateWorkerClientOptions mapping + defaults (fail under a mutated mapping), alias honoured, both-keys conflict, and bounds for the new options. Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// mxaccessgw#192: the deprecated <c>HeartbeatIntervalSeconds</c> key still sets the
|
||||
/// heartbeat check interval, so existing configuration keeps its meaning after the rename.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void HeartbeatIntervalSeconds_DeprecatedAlias_SetsCheckInterval()
|
||||
{
|
||||
GatewayOptions options = BindOptions(new Dictionary<string, string?>
|
||||
{
|
||||
["MxGateway:Ldap:ServiceAccountPassword"] = "test-bind-password",
|
||||
["MxGateway:Worker:HeartbeatIntervalSeconds"] = "7",
|
||||
});
|
||||
|
||||
Assert.Equal(7, options.Worker.ResolveHeartbeatCheckIntervalSeconds());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// mxaccessgw#192: setting both the new key and its deprecated alias is ambiguous and
|
||||
/// fails validation rather than silently preferring one.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void HeartbeatCheckInterval_BothKeysSet_FailsValidation()
|
||||
{
|
||||
OptionsValidationException exception = Assert.Throws<OptionsValidationException>(() =>
|
||||
_ = BindOptions(new Dictionary<string, string?>
|
||||
{
|
||||
["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));
|
||||
}
|
||||
|
||||
/// <summary>Verifies that pepper secret names are redacted in the effective configuration.</summary>
|
||||
[Fact]
|
||||
public void EffectiveConfiguration_RedactsPepperSecretName()
|
||||
|
||||
@@ -317,7 +317,7 @@ public sealed class GatewayEndToEndFakeWorkerSmokeTests
|
||||
{
|
||||
StartupTimeoutSeconds = 5,
|
||||
ShutdownTimeoutSeconds = 5,
|
||||
HeartbeatIntervalSeconds = 30,
|
||||
HeartbeatCheckIntervalSeconds = 30,
|
||||
HeartbeatGraceSeconds = 30,
|
||||
MaxMessageBytes = WorkerFrameProtocolOptions.DefaultMaxMessageBytes,
|
||||
},
|
||||
|
||||
@@ -528,7 +528,7 @@ public sealed class GatewayEndToEndMultiSubscriberTests(ITestOutputHelper output
|
||||
{
|
||||
StartupTimeoutSeconds = 5,
|
||||
ShutdownTimeoutSeconds = 5,
|
||||
HeartbeatIntervalSeconds = 30,
|
||||
HeartbeatCheckIntervalSeconds = 30,
|
||||
HeartbeatGraceSeconds = 30,
|
||||
MaxMessageBytes = WorkerFrameProtocolOptions.DefaultMaxMessageBytes,
|
||||
},
|
||||
|
||||
@@ -644,7 +644,7 @@ public sealed class GatewayEndToEndReconnectReplayTests(ITestOutputHelper output
|
||||
{
|
||||
StartupTimeoutSeconds = 5,
|
||||
ShutdownTimeoutSeconds = 5,
|
||||
HeartbeatIntervalSeconds = 30,
|
||||
HeartbeatCheckIntervalSeconds = 30,
|
||||
HeartbeatGraceSeconds = 30,
|
||||
MaxMessageBytes = WorkerFrameProtocolOptions.DefaultMaxMessageBytes,
|
||||
},
|
||||
|
||||
+47
-1
@@ -124,6 +124,52 @@ public sealed class SessionWorkerClientFactoryFakeWorkerTests : IAsyncLifetime
|
||||
Assert.True(launcher.Process.IsDisposed);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// mxaccessgw#192: every <see cref="WorkerClientOptions"/> field comes from configuration.
|
||||
/// The heartbeat check interval binds from <c>HeartbeatCheckIntervalSeconds</c> (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.
|
||||
/// </summary>
|
||||
[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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[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,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user