fix(abcip): #983 packed structure reads, non-blocking lease release, allocation trims, docs (P-24)
Structure reads of a known size pack into one MSP; browse/template lease release no longer blocks a thread-pool thread up to 2 s; scheduler packs with running totals; CipReply empty extended-status array shared. AbCip.md documents P-2/P-13/P-16/P-22/P-23/P-24.
This commit is contained in:
@@ -81,6 +81,33 @@ public sealed class NativeAbCipTagEnumeratorTests
|
||||
return tags;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// P-24 (#983): the lease release (a Forward Close) must not be waited on from the async iterator's
|
||||
/// <c>finally</c> — it used to block a thread-pool thread for up to 2 s per browse. A release that never
|
||||
/// completes must not delay the enumeration; it is still started exactly once.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task A_slow_lease_release_does_not_delay_the_enumeration()
|
||||
{
|
||||
var ch = Serve(new() { [""] = Entries(CipSymbolObjectRealControllerCaptureTests.WwInCycle) });
|
||||
var neverCloses = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var releases = 0;
|
||||
await using var sched = new RequestScheduler(ch, allowPacking: false);
|
||||
using var enumerator = new NativeAbCipTagEnumerator(_ =>
|
||||
(sched, () => { Interlocked.Increment(ref releases); return new ValueTask(neverCloses.Task); }));
|
||||
|
||||
var tags = new List<AbCipDiscoveredTag>();
|
||||
var sw = System.Diagnostics.Stopwatch.StartNew();
|
||||
await foreach (var t in enumerator.EnumerateAsync(Params, TestContext.Current.CancellationToken))
|
||||
tags.Add(t);
|
||||
sw.Stop();
|
||||
|
||||
tags.ShouldContain(t => t.Name == "WW_InCycle"); // positive control: it enumerated
|
||||
releases.ShouldBe(1);
|
||||
sw.Elapsed.ShouldBeLessThan(TimeSpan.FromMilliseconds(1500)); // unfixed: held for the 2 s DisposeWait
|
||||
neverCloses.SetResult();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Paged_controller_and_program_listings_decode_identically_to_the_captured_buffers()
|
||||
{
|
||||
|
||||
@@ -410,6 +410,33 @@ public sealed class NativeAbCipTagRuntimeTests
|
||||
bits.Select((b, i) => b == (i % 2 == 1)).ShouldAllBe(ok => ok); // byte i, not bit i
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// P-24 (#983): a Structure read has no static element width, so every one was sent alone (UnknownReply). After
|
||||
/// the first read the size is known and queued structure reads pack into one Multiple Service Packet.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task Structure_reads_of_a_known_size_pack_into_one_MSP()
|
||||
{
|
||||
var udt = Convert.FromHexString("A002CE0F" + new string('1', 40)); // struct handle + 20 data bytes
|
||||
var ch = new FakeCipChannel { RespondPerService = req => Convert.FromHexString("D2000000").Concat(udt).ToArray() };
|
||||
using var rt = NativeAbCipTagRuntime.ForTest(ch, Params("Motor", AbCipDataType.Structure) with { AllowPacking = true });
|
||||
await rt.InitializeAsync(CancellationToken.None); // learns the size
|
||||
ch.SentCount.ShouldBe(1);
|
||||
|
||||
ch.Gate = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var a = rt.ReadAsync(CancellationToken.None);
|
||||
await ch.WaitForSendsAsync(2); // `a` is in flight; the next two queue behind it
|
||||
var b = rt.ReadAsync(CancellationToken.None);
|
||||
var c = rt.ReadAsync(CancellationToken.None);
|
||||
var d = rt.ReadAsync(CancellationToken.None);
|
||||
ch.Gate.SetResult();
|
||||
await Task.WhenAll(a, b, c, d).WaitAsync(TimeSpan.FromSeconds(10), TestContext.Current.CancellationToken);
|
||||
|
||||
ch.SentCount.ShouldBe(3); // init, a alone, ONE packed MSP for b + c + d
|
||||
ch.Sent[2][0].ShouldBe((byte)0x0A);
|
||||
FakeCipChannel.SplitMsp(ch.Sent[2]).Count.ShouldBe(3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task A_user_string_array_uses_the_buffer_derived_stride()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user