fix: preserve SDK 2.0 client value and lifetime contracts
This commit is contained in:
+42
@@ -11,6 +11,48 @@ namespace ZB.MOM.WW.OtOpcUa.Client.Shared.Tests.Adapters;
|
||||
/// </summary>
|
||||
public class DefaultSubscriptionAdapterTests
|
||||
{
|
||||
private sealed class CountingSubscription() : Subscription(ClientTelemetry.Context)
|
||||
{
|
||||
public int DisposeCount;
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing) Interlocked.Increment(ref DisposeCount);
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DeleteAndDispose_ReleaseSdkResourcesExactlyOnce()
|
||||
{
|
||||
var subscription = new CountingSubscription();
|
||||
var detached = 0;
|
||||
var adapter = new DefaultSubscriptionAdapter(subscription, (_, _) =>
|
||||
{
|
||||
Interlocked.Increment(ref detached);
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
await adapter.DeleteAsync(TestContext.Current.CancellationToken);
|
||||
adapter.Dispose();
|
||||
adapter.Dispose();
|
||||
detached.ShouldBe(1);
|
||||
subscription.DisposeCount.ShouldBe(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ConcurrentTeardown_HasOneSdkResourceOwner()
|
||||
{
|
||||
var subscription = new CountingSubscription();
|
||||
var detached = 0;
|
||||
var adapter = new DefaultSubscriptionAdapter(subscription, (_, _) =>
|
||||
{
|
||||
Interlocked.Increment(ref detached);
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
await Task.WhenAll(Task.Run(adapter.Dispose, TestContext.Current.CancellationToken), adapter.DeleteAsync(TestContext.Current.CancellationToken));
|
||||
detached.ShouldBe(1);
|
||||
subscription.DisposeCount.ShouldBe(1);
|
||||
}
|
||||
|
||||
/// <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()
|
||||
|
||||
Reference in New Issue
Block a user