fix(opcuaclient): split the per-endpoint connect budget into reachability + session phases (#912)
PerEndpointConnectTimeout (3 s) now bounds only TCP + discovery, so failover past a dead endpoint stays fast. The new SessionCreateTimeout (10 s) bounds OpenSecureChannel + CreateSession on an endpoint that answered discovery, where the client-side cert and crypto work lives (#910). 2 x (3 + 10) s stays inside the host's 30 s initialise bound. Expiries name the budget that ran out; both budgets must be positive; AdminUI form carries the new field so a save does not drop it; driver docs updated. Closes #912
This commit is contained in:
@@ -109,4 +109,73 @@ public sealed class OpcUaClientFailoverTests
|
||||
ex.Message.ShouldContain("TimeoutException");
|
||||
ex.Message.ShouldContain("PerEndpointConnectTimeout (0.4 s)");
|
||||
}
|
||||
|
||||
/// <summary>#912: the two connect phases default to a short reachability budget and a larger session budget.</summary>
|
||||
[Fact]
|
||||
public void Connect_budgets_default_to_3s_reachability_and_10s_session()
|
||||
{
|
||||
var o = new OpcUaClientDriverOptions();
|
||||
o.PerEndpointConnectTimeout.ShouldBe(TimeSpan.FromSeconds(3));
|
||||
o.SessionCreateTimeout.ShouldBe(TimeSpan.FromSeconds(10));
|
||||
// Two candidates that both hang in the session phase must still fit the host's initialise bound.
|
||||
(2 * (o.PerEndpointConnectTimeout + o.SessionCreateTimeout)).ShouldBeLessThan(TimeSpan.FromSeconds(30));
|
||||
}
|
||||
|
||||
/// <summary>#912: a phase cut short by its own budget is reported as that budget, by option name.</summary>
|
||||
[Fact]
|
||||
public async Task A_phase_budget_expiry_names_its_option()
|
||||
{
|
||||
var ex = await Should.ThrowAsync<TimeoutException>(() => OpcUaClientDriver.RunWithinBudgetAsync<int>(
|
||||
TimeSpan.FromMilliseconds(100), nameof(OpcUaClientDriverOptions.SessionCreateTimeout),
|
||||
async budget => { await Task.Delay(Timeout.Infinite, budget); return 0; },
|
||||
TestContext.Current.CancellationToken));
|
||||
|
||||
ex.Message.ShouldContain("SessionCreateTimeout (0.1 s)");
|
||||
ex.InnerException.ShouldBeAssignableTo<OperationCanceledException>();
|
||||
}
|
||||
|
||||
/// <summary>#912: a caller cancel is not dressed up as a budget expiry.</summary>
|
||||
[Fact]
|
||||
public async Task A_caller_cancel_passes_through_unchanged()
|
||||
{
|
||||
using var caller = new CancellationTokenSource(TimeSpan.FromMilliseconds(100));
|
||||
await Should.ThrowAsync<OperationCanceledException>(() => OpcUaClientDriver.RunWithinBudgetAsync<int>(
|
||||
TimeSpan.FromSeconds(30), "X",
|
||||
async budget => { await Task.Delay(Timeout.Infinite, budget); return 0; },
|
||||
caller.Token));
|
||||
}
|
||||
|
||||
/// <summary>#912: a phase that completes inside its budget returns its result, and a non-timeout fault is not rewritten.</summary>
|
||||
[Fact]
|
||||
public async Task A_phase_inside_its_budget_returns_and_faults_pass_through()
|
||||
{
|
||||
(await OpcUaClientDriver.RunWithinBudgetAsync(TimeSpan.FromSeconds(5), "X",
|
||||
_ => Task.FromResult(42), TestContext.Current.CancellationToken)).ShouldBe(42);
|
||||
|
||||
await Should.ThrowAsync<InvalidOperationException>(() => OpcUaClientDriver.RunWithinBudgetAsync<int>(
|
||||
TimeSpan.FromSeconds(5), "X", _ => throw new InvalidOperationException("boom"),
|
||||
TestContext.Current.CancellationToken));
|
||||
}
|
||||
|
||||
/// <summary>#912: non-positive connect budgets are refused at initialise.</summary>
|
||||
[Fact]
|
||||
public void ValidateTuning_rejects_non_positive_connect_budgets()
|
||||
{
|
||||
Should.Throw<InvalidOperationException>(() => OpcUaClientDriver.ValidateTuning(
|
||||
new OpcUaClientDriverOptions { SessionCreateTimeout = TimeSpan.Zero }))
|
||||
.Message.ShouldContain("SessionCreateTimeout");
|
||||
Should.Throw<InvalidOperationException>(() => OpcUaClientDriver.ValidateTuning(
|
||||
new OpcUaClientDriverOptions { PerEndpointConnectTimeout = TimeSpan.Zero }))
|
||||
.Message.ShouldContain("PerEndpointConnectTimeout");
|
||||
}
|
||||
|
||||
/// <summary>#912: the factory binds <c>sessionCreateTimeout</c>; JSON without it keeps the default.</summary>
|
||||
[Fact]
|
||||
public void Factory_binds_sessionCreateTimeout()
|
||||
{
|
||||
OpcUaClientDriverFactoryExtensions.ParseOptions("d", """{"sessionCreateTimeout":"00:00:20"}""")
|
||||
.SessionCreateTimeout.ShouldBe(TimeSpan.FromSeconds(20));
|
||||
OpcUaClientDriverFactoryExtensions.ParseOptions("d", "{}")
|
||||
.SessionCreateTimeout.ShouldBe(TimeSpan.FromSeconds(10));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user