fix(mtconnect): the Agent refuses count ABOVE bufferSize, not at it (#825)

Live gate against the cppagent 2.7 fixture: count=16384 with bufferSize
16384 streams; 16385 is OUT_OF_RANGE ('count' must be less than 16385).
Warn only when SampleCount > bufferSize, pin both sides of the edge
against the live Agent, and correct the #804 wording that said 'at or
above'.
This commit is contained in:
Joseph Doherty
2026-11-11 01:38:48 -05:00
parent f8f6781a24
commit 8a6f0e3c84
11 changed files with 41 additions and 29 deletions
@@ -868,7 +868,7 @@ public sealed class MTConnectAgentIntegrationTests(MTConnectAgentFixture agent)
}
/// <summary>
/// #804 — a <c>SampleCount</c> at or above the Agent's <c>bufferSize</c> is refused <c>OUT_OF_RANGE</c> on
/// #804 — a <c>SampleCount</c> above the Agent's <c>bufferSize</c> is refused <c>OUT_OF_RANGE</c> on
/// EVERY <c>/sample</c> open (live: <c>'count' must be less than N</c>). The driver keeps serving values off
/// <c>/current</c> re-baselines, and — after three in a row with no <c>/sample</c> chunk — reports the stream
/// Degraded with <c>LastSuccessfulRead</c> still advancing, rather than Healthy for ever (before #804 the
@@ -949,7 +949,8 @@ public sealed class MTConnectAgentIntegrationTests(MTConnectAgentFixture agent)
/// <summary>
/// #825 — Test Connect reads the live Agent's <c>/probe</c> <c>bufferSize</c> and warns (still Ok) when the
/// configured <c>SampleCount</c> would be refused; one below the buffer is the falsifiability control.
/// configured <c>SampleCount</c> would be refused. The live Agent accepts <c>count == bufferSize</c> and refuses
/// <c>bufferSize + 1</c>, so both sides of that edge are checked against the Agent itself as well as the probe.
/// </summary>
[Fact(Timeout = TestTimeoutMs)]
public async Task Test_Connect_warns_when_SampleCount_reaches_the_live_agents_buffer_size()
@@ -963,14 +964,22 @@ public sealed class MTConnectAgentIntegrationTests(MTConnectAgentFixture agent)
Assert.Skip($"The Agent at {agent.AgentUri} declares no usable bufferSize in its /probe header.");
}
// The Agent's own edge, so the warning threshold is pinned to what the Agent actually does.
using (var http = new HttpClient { Timeout = TimeSpan.FromSeconds(15) })
{
(await http.GetStringAsync($"{agent.AgentUri}/sample?count={bufferSize.Value}", Ct)).ShouldNotContain("OUT_OF_RANGE");
var over = await http.GetAsync($"{agent.AgentUri}/sample?count={bufferSize.Value + 1}", Ct);
(await over.Content.ReadAsStringAsync(Ct)).ShouldContain("OUT_OF_RANGE");
}
var refused = await new MTConnectDriverProbe().ProbeAsync(
JsonSerializer.Serialize(new { agentUri = agent.AgentUri, sampleCount = bufferSize.Value }),
JsonSerializer.Serialize(new { agentUri = agent.AgentUri, sampleCount = bufferSize.Value + 1 }),
TimeSpan.FromSeconds(15), Ct);
refused.Ok.ShouldBeTrue(refused.Message);
refused.Message!.ShouldContain($"WARNING: SampleCount {bufferSize.Value} is at or above the Agent's bufferSize {bufferSize.Value}");
refused.Message!.ShouldContain($"WARNING: SampleCount {bufferSize.Value + 1} is above the Agent's bufferSize {bufferSize.Value}");
var fits = await new MTConnectDriverProbe().ProbeAsync(
JsonSerializer.Serialize(new { agentUri = agent.AgentUri, sampleCount = bufferSize.Value - 1 }),
JsonSerializer.Serialize(new { agentUri = agent.AgentUri, sampleCount = bufferSize.Value }),
TimeSpan.FromSeconds(15), Ct);
fits.Ok.ShouldBeTrue(fits.Message);
fits.Message!.ShouldNotContain("WARNING");
@@ -7,7 +7,7 @@ using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
namespace ZB.MOM.WW.OtOpcUa.Driver.MTConnect.Tests;
/// <summary>
/// lmxopcua#825 — a <c>SampleCount</c> at or above the Agent's <c>bufferSize</c> is refused <c>OUT_OF_RANGE</c> on
/// lmxopcua#825 — a <c>SampleCount</c> above the Agent's <c>bufferSize</c> is refused <c>OUT_OF_RANGE</c> on
/// every <c>/sample</c> stream. The <c>/probe</c> header carries <c>bufferSize</c>, so Test Connect and the
/// driver's initialize (deploy) both warn instead of leaving it to surface as a Degraded stream.
/// </summary>
@@ -37,15 +37,15 @@ public sealed class MTConnectBufferSizeWarningTests
MTConnectProbeParser.Parse(ProbeXml(attribute)).BufferSize.ShouldBe(expected);
[Theory]
[InlineData(16383, 16384L, false)]
[InlineData(16384, 16384L, true)]
[InlineData(16384, 16384L, false)] // live, cppagent 2.7: count == bufferSize is accepted
[InlineData(16385, 16384L, true)] // ... and bufferSize + 1 refused OUT_OF_RANGE
[InlineData(20000, 16384L, true)]
[InlineData(1_000_000, null, false)]
public void The_warning_fires_exactly_at_and_above_the_buffer_size(int sampleCount, long? bufferSize, bool warns)
public void The_warning_fires_only_above_the_buffer_size(int sampleCount, long? bufferSize, bool warns)
{
var warning = MTConnectDriver.SampleCountBufferWarning(sampleCount, bufferSize);
(warning is not null).ShouldBe(warns);
if (warns) warning!.ShouldContain($"below {bufferSize}");
if (warns) warning!.ShouldContain($"at most {bufferSize}");
}
[Fact]
@@ -53,7 +53,7 @@ public sealed class MTConnectBufferSizeWarningTests
{
var probe = new MTConnectDriverProbe(new StubHandler(ProbeXml("16384")));
var r = await probe.ProbeAsync(
"{\"agentUri\":\"http://stub-agent:5000\",\"sampleCount\":16384}", TimeSpan.FromSeconds(3),
"{\"agentUri\":\"http://stub-agent:5000\",\"sampleCount\":16385}", TimeSpan.FromSeconds(3),
TestContext.Current.CancellationToken);
r.Ok.ShouldBeTrue("the Agent answered — reachability is not the problem");
@@ -70,7 +70,7 @@ public sealed class MTConnectBufferSizeWarningTests
"{\"agentUri\":\"http://stub-agent:5000\"}", TimeSpan.FromSeconds(3), TestContext.Current.CancellationToken);
r.Ok.ShouldBeTrue();
r.Message!.ShouldContain("SampleCount 1000 is at or above the Agent's bufferSize 512");
r.Message!.ShouldContain("SampleCount 1000 is above the Agent's bufferSize 512");
}
[Fact]
@@ -78,7 +78,7 @@ public sealed class MTConnectBufferSizeWarningTests
{
var probe = new MTConnectDriverProbe(new StubHandler(ProbeXml("16384")));
var r = await probe.ProbeAsync(
"{\"agentUri\":\"http://stub-agent:5000\",\"sampleCount\":1000}", TimeSpan.FromSeconds(3),
"{\"agentUri\":\"http://stub-agent:5000\",\"sampleCount\":16384}", TimeSpan.FromSeconds(3),
TestContext.Current.CancellationToken);
r.Ok.ShouldBeTrue();
@@ -86,7 +86,8 @@ public sealed class MTConnectBufferSizeWarningTests
}
[Theory]
[InlineData(131072, true)]
[InlineData(131073, true)]
[InlineData(131072, false)]
[InlineData(1000, false)]
public async Task Initialize_warns_and_surfaces_the_buffer_size_on_the_diagnostics_bag(int sampleCount, bool warns)
{
@@ -1168,7 +1168,7 @@ public sealed class MTConnectSubscribeTests
/// <summary>
/// <b>#804 (Java-driver parity: <c>MAX_REBASELINES_WITHOUT_PROGRESS</c>).</b> An Agent that answers EVERY
/// <c>/sample</c> open with <c>OUT_OF_RANGE</c> (live: a <c>count</c> at or above its <c>bufferSize</c>) is
/// <c>/sample</c> open with <c>OUT_OF_RANGE</c> (live: a <c>count</c> above its <c>bufferSize</c>) is
/// re-baselined from <c>/current</c> each time, and the backoff paces that — but every re-baseline also marked
/// the stream delivered, so the driver read <b>Healthy</b> for ever while not one <c>/sample</c> chunk arrived.
/// After <see cref="MTConnectDriver.MaxRebaselinesWithoutProgress"/> in a row it is Degraded and stays so