test: validate grpc data connections with local docker and opcua cli
This commit is contained in:
@@ -38,6 +38,8 @@ internal sealed class DataWriteExecutor(DataAuthenticatedContext context, Func<L
|
||||
public async Task<IReadOnlyList<WriteItemResult>> WriteAsync(WriteBatch request, CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(request);
|
||||
// The caller's budget covers validation and all batch preflight work.
|
||||
var started = clock.GetTimestamp();
|
||||
ArgumentNullException.ThrowIfNull(request.Items);
|
||||
request.Budget.Validate();
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
@@ -51,7 +53,6 @@ internal sealed class DataWriteExecutor(DataAuthenticatedContext context, Func<L
|
||||
totalBytes = checked(totalBytes + RetainedBytes(item));
|
||||
}
|
||||
if (totalBytes > request.Budget.MaxBytes) throw new ArgumentOutOfRangeException(nameof(request), "Write batch exceeds its byte limit.");
|
||||
var started = clock.GetTimestamp();
|
||||
var pending = request.Items.Select(item => ExecuteItem(item, request.Budget, started, cancellationToken)).ToArray();
|
||||
return await Task.WhenAll(pending).ConfigureAwait(false);
|
||||
}
|
||||
@@ -94,12 +95,37 @@ internal sealed class DataWriteExecutor(DataAuthenticatedContext context, Func<L
|
||||
return new(item.CorrelationId, existing);
|
||||
}
|
||||
|
||||
var remaining = budget.Timeout - clock.GetElapsedTime(start);
|
||||
if (item.RemainingBudget < remaining) remaining = item.RemainingBudget;
|
||||
// Preserve one absolute request deadline, including the per-item bound; do not
|
||||
// restart it after route lookup, byte admission, or retained-value preparation.
|
||||
var allowance = item.RemainingBudget < budget.Timeout ? item.RemainingBudget : budget.Timeout;
|
||||
long expiration;
|
||||
try
|
||||
{
|
||||
if (allowance <= TimeSpan.Zero) throw new ArgumentOutOfRangeException(nameof(item));
|
||||
var timestampTicks = checked((long)((decimal)allowance.Ticks * clock.TimestampFrequency / TimeSpan.TicksPerSecond));
|
||||
expiration = checked(start + timestampTicks);
|
||||
}
|
||||
catch (Exception ex) when (ex is OverflowException or ArgumentException)
|
||||
{
|
||||
var rejected = Rejected("Invalid write deadline or value.");
|
||||
claim.Complete(rejected);
|
||||
return new(item.CorrelationId, rejected);
|
||||
}
|
||||
bool HasDispatchBudget(long now)
|
||||
{
|
||||
try
|
||||
{
|
||||
var elapsed = clock.GetElapsedTime(start, now);
|
||||
return elapsed >= TimeSpan.Zero && elapsed < allowance && now < expiration &&
|
||||
allowance - elapsed >= bounds.GatewayAsk;
|
||||
}
|
||||
catch (Exception ex) when (ex is ArgumentException or OverflowException) { return false; }
|
||||
}
|
||||
WriteRouteTarget? target;
|
||||
try { target = remaining >= bounds.GatewayAsk && route.TryResolve(node.Metadata.View, out var resolved) ? resolved : null; }
|
||||
try { target = !cancellationToken.IsCancellationRequested && HasDispatchBudget(clock.GetTimestamp()) &&
|
||||
route.TryResolve(node.Metadata.View, out var resolved) ? resolved : null; }
|
||||
catch { target = null; }
|
||||
if (target is null)
|
||||
if (target is null || cancellationToken.IsCancellationRequested || !HasDispatchBudget(clock.GetTimestamp()))
|
||||
{
|
||||
var rejected = Rejected("Insufficient budget or no active driver route.");
|
||||
claim.Complete(rejected);
|
||||
@@ -116,7 +142,6 @@ internal sealed class DataWriteExecutor(DataAuthenticatedContext context, Func<L
|
||||
try
|
||||
{
|
||||
var issued = clock.GetTimestamp();
|
||||
var expiration = checked(issued + (long)(remaining.TotalSeconds * clock.TimestampFrequency));
|
||||
var admission = new DataWriteAdmission(context.PrincipalId, node.Metadata.View, current.AuthorityEpoch,
|
||||
current.Serving.CatalogEpoch, current.Serving.Incarnation, target.DriverIncarnation, item.OperationId,
|
||||
expiration, context.ApiKeyId, context.CredentialExpiresUtc, context.CredentialVersion);
|
||||
@@ -132,6 +157,13 @@ internal sealed class DataWriteExecutor(DataAuthenticatedContext context, Func<L
|
||||
claim.Complete(rejected);
|
||||
return new(item.CorrelationId, rejected);
|
||||
}
|
||||
if (cancellationToken.IsCancellationRequested || !HasDispatchBudget(clock.GetTimestamp()))
|
||||
{
|
||||
ticket.Dispose();
|
||||
var rejected = Rejected("Insufficient budget or no active driver route.");
|
||||
claim.Complete(rejected);
|
||||
return new(item.CorrelationId, rejected);
|
||||
}
|
||||
_ = DispatchAsync(route, ticket, claim);
|
||||
return new(item.CorrelationId, await claim.Completion.WaitAsync(cancellationToken).ConfigureAwait(false));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user