fix(client): release a capped HistoryRead cursor, read (not release) follow-up pages, detach deleted subscriptions
R08 1.4: raw and modified history reads share HistoryReadPaging. A read stopped by the caller's cap releases the server continuation point. The raw path also passed releaseContinuationPoints = (cp != null), which released page two instead of reading it, so every raw read was silently truncated to its first server page. R08 1.5: DefaultSubscriptionAdapter removes its Subscription from the SDK Session on delete/dispose (and a failed CreateAsync removes it too), so re-targeted alarm subscriptions no longer accumulate in Session.Subscriptions. Refs #747 Claude-Session: https://claude.ai/code/session_01Ub9hGmYLQvn9XETzw7CMsT
This commit is contained in:
+57
@@ -0,0 +1,57 @@
|
||||
using Opc.Ua.Client;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.Client.Shared.Adapters;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Client.Shared.Tests.Adapters;
|
||||
|
||||
/// <summary>
|
||||
/// A deleted subscription must also leave the SDK session's <c>Subscriptions</c> list, or every alarm re-target in the UI
|
||||
/// leaves a dead <see cref="Subscription"/> behind until the session is disposed.
|
||||
/// </summary>
|
||||
public class DefaultSubscriptionAdapterTests
|
||||
{
|
||||
/// <summary>DeleteAsync detaches the wrapped subscription exactly once, even when Dispose follows.</summary>
|
||||
[Fact]
|
||||
public async Task DeleteAsync_detaches_the_subscription_from_its_session_once()
|
||||
{
|
||||
var subscription = new Subscription();
|
||||
var detached = new List<Subscription>();
|
||||
var adapter = new DefaultSubscriptionAdapter(subscription, (s, _) =>
|
||||
{
|
||||
lock (detached) detached.Add(s);
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
|
||||
await adapter.DeleteAsync(TestContext.Current.CancellationToken);
|
||||
adapter.Dispose();
|
||||
|
||||
detached.ShouldHaveSingleItem().ShouldBeSameAs(subscription);
|
||||
}
|
||||
|
||||
/// <summary>Dispose alone (no prior DeleteAsync) detaches too.</summary>
|
||||
[Fact]
|
||||
public void Dispose_detaches_the_subscription_from_its_session()
|
||||
{
|
||||
var detached = 0;
|
||||
var adapter = new DefaultSubscriptionAdapter(new Subscription(), (_, _) =>
|
||||
{
|
||||
Interlocked.Increment(ref detached);
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
|
||||
adapter.Dispose();
|
||||
|
||||
detached.ShouldBe(1);
|
||||
}
|
||||
|
||||
/// <summary>A failing detach is logged, not thrown: teardown stays best effort.</summary>
|
||||
[Fact]
|
||||
public async Task A_failing_detach_does_not_throw_from_DeleteAsync()
|
||||
{
|
||||
var adapter = new DefaultSubscriptionAdapter(new Subscription(),
|
||||
(_, _) => throw new InvalidOperationException("boom"));
|
||||
|
||||
await Should.NotThrowAsync(() => adapter.DeleteAsync(TestContext.Current.CancellationToken));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user