fix: preserve SDK 2.0 client value and lifetime contracts

This commit is contained in:
Joseph Doherty
2026-11-10 10:19:42 -05:00
parent 0ecea3c6be
commit 3ca06e1b87
38 changed files with 591 additions and 186 deletions
@@ -35,7 +35,7 @@ internal sealed class FakeEndpointDiscovery : IEndpointDiscovery
: SecurityPolicies.Basic256Sha256,
Server = new ApplicationDescription
{
ApplicationName = "FakeServer",
ApplicationName = new LocalizedText("FakeServer"),
ApplicationUri = "urn:localhost:FakeServer"
}
});
@@ -48,11 +48,15 @@ internal sealed class FakeSessionAdapter : ISessionAdapter
public bool ThrowOnBrowse { get; set; }
/// <summary>Gets or sets the browse references returned by browse operations.</summary>
public ReferenceDescriptionCollection BrowseResponse { get; set; } = [];
public ArrayOf<ReferenceDescription> BrowseResponse { get; set; } = [];
/// <summary>Gets or sets the continuation point for browse operations.</summary>
public byte[]? BrowseContinuationPoint { get; set; }
public Func<CancellationToken, Task>? BeforeBrowseNext { get; set; }
public List<(byte[] Point, bool Cancelled)> BrowseReleases { get; } = [];
public bool ThrowOnBrowseRelease { get; set; }
/// <summary>Gets or sets the browse references returned by browse-next operations.</summary>
public ReferenceDescriptionCollection BrowseNextResponse { get; set; } = [];
public ArrayOf<ReferenceDescription> BrowseNextResponse { get; set; } = [];
/// <summary>Gets or sets the continuation point for browse-next operations.</summary>
public byte[]? BrowseNextContinuationPoint { get; set; }
@@ -129,7 +133,7 @@ internal sealed class FakeSessionAdapter : ISessionAdapter
}
/// <inheritdoc />
public Task<(byte[]? ContinuationPoint, ReferenceDescriptionCollection References)> BrowseAsync(
public Task<(byte[]? ContinuationPoint, ArrayOf<ReferenceDescription> References)> BrowseAsync(
NodeId nodeId, uint nodeClassMask, CancellationToken ct)
{
BrowseCount++;
@@ -139,11 +143,19 @@ internal sealed class FakeSessionAdapter : ISessionAdapter
}
/// <inheritdoc />
public Task<(byte[]? ContinuationPoint, ReferenceDescriptionCollection References)> BrowseNextAsync(
public async Task<(byte[]? ContinuationPoint, ArrayOf<ReferenceDescription> References)> BrowseNextAsync(
byte[] continuationPoint, CancellationToken ct)
{
BrowseNextCount++;
return Task.FromResult((BrowseNextContinuationPoint, BrowseNextResponse));
if (BeforeBrowseNext != null) await BeforeBrowseNext(ct);
return (BrowseNextContinuationPoint, BrowseNextResponse);
}
public Task ReleaseBrowseContinuationPointAsync(byte[] continuationPoint, CancellationToken ct)
{
BrowseReleases.Add((continuationPoint, ct.IsCancellationRequested));
if (ThrowOnBrowseRelease) throw new ServiceResultException(StatusCodes.BadSessionClosed);
return Task.CompletedTask;
}
/// <inheritdoc />
@@ -40,7 +40,7 @@ internal sealed class FakeSessionFactory : ISessionFactory
uint sessionTimeoutMs, UserIdentity identity, CancellationToken ct)
{
CreateCallCount++;
LastEndpointUrl = endpoint.EndpointUrl;
LastEndpointUrl = endpoint.EndpointUrl ?? string.Empty;
// One-shot: the gate holds only the call that observed it, so a later call (e.g. a user's Connect while a
// failover is held) runs freely.
@@ -60,14 +60,14 @@ internal sealed class FakeSessionFactory : ISessionFactory
else
session = new FakeSessionAdapter
{
EndpointUrl = endpoint.EndpointUrl,
ServerName = endpoint.Server?.ApplicationName?.Text ?? "FakeServer",
EndpointUrl = endpoint.EndpointUrl ?? string.Empty,
ServerName = endpoint.Server?.ApplicationName.Text ?? "FakeServer",
SecurityMode = endpoint.SecurityMode.ToString(),
SecurityPolicyUri = endpoint.SecurityPolicyUri ?? string.Empty
};
// Ensure endpoint URL matches
session.EndpointUrl = endpoint.EndpointUrl;
session.EndpointUrl = endpoint.EndpointUrl ?? string.Empty;
_createdSessions.Add(session);
return session;
}
@@ -129,6 +129,16 @@ internal sealed class FakeSubscriptionAdapter : ISubscriptionAdapter
lock (_itemsLock) _items.Clear();
}
public Action<string, DataValue> CaptureDataCallback(uint handle)
{
lock (_itemsLock) return _items[handle].DataCallback!;
}
public Action<EventFieldList> CaptureEventCallback(uint handle)
{
lock (_itemsLock) return _items[handle].EventCallback!;
}
/// <summary>
/// Simulates a data change notification for testing.
/// </summary>