test(grpc-data): opt-in H2 history profile for the standalone rig (SqlServer historian overlay, history seed grants, probe HistoryRead, smoke runner)

This commit is contained in:
Joseph Doherty
2026-11-23 23:13:31 -05:00
parent abc6a1b068
commit eb29360d47
6 changed files with 344 additions and 11 deletions
@@ -10,7 +10,8 @@ public sealed record ProbeCommand(string Id, string ConnectionId, string Operati
string? ExpectedRole = null, string? ExpectedState = null, string? Continuation = null,
long? ExpectedCatalogRevision = null, string? ExpectedIncarnation = null, long? ExpectedGeneration = null,
WorkloadOptions? Workload = null, string? WorkloadUnsNamespaceUri = null,
IReadOnlyDictionary<string, string>? WorkloadBrowseRoots = null, int? MaximumAgeMilliseconds = 5000);
IReadOnlyDictionary<string, string>? WorkloadBrowseRoots = null, int? MaximumAgeMilliseconds = 5000,
DateTimeOffset? HistoryStartUtc = null, DateTimeOffset? HistoryEndUtc = null, uint HistoryNumValues = 5);
public sealed record ProbeResult(string Id, string Operation, bool Passed, int Assertions,
Dictionary<string, object?> Observations, string? Failure = null);
@@ -234,6 +235,63 @@ public static class ProbeEngine
observations["distinctValues"] = values.Count;
observations["lastSequence"] = lastSequence;
}
else if (command.Operation == "history")
{
// H2 smoke: a Raw HistoryRead through whatever IDataConnection the caller holds (the deployed lease on a
// consumer node, or a probe-built GrpcDataConnection). ExpectedState: Good (default) | Unsupported.
phase = ProbeFailurePhase.Read;
Check(connection is IDataHistoryService, "connection serves history");
var history = (IDataHistoryService)connection;
observations["historyCapabilities"] = caps.History;
observations["historyReadAdvertised"] = caps.Operations.HasFlag(DataOperations.HistoryRead);
var details = new DataHistoryRawDetails(command.HistoryStartUtc, command.HistoryEndUtc ?? DateTimeOffset.UtcNow,
command.HistoryNumValues, false);
var historyBudget = budget with { MaxBytes = 4 * 1024 * 1024 };
static object Page(DataHistoryReadResult result) => new
{
statusCode = "0x" + result.StatusCode.ToString("X8"), result.Diagnostic, hasContinuation = result.Continuation is not null,
samples = result.Samples.Select(sample => new
{
value = ZB.MOM.WW.OtOpcUa.Commons.DataConnections.TypedValueCodec.Encode(sample.Value).ToString(),
statusCode = "0x" + sample.StatusCode.ToString("X8"), sourceTimestampUtc = sample.SourceTimestampUtc?.ToString("O"),
serverTimestampUtc = sample.ServerTimestampUtc?.ToString("O"),
}).ToArray(),
};
var pages = new List<object>();
observations["pages"] = pages;
var first = await history.ReadAsync(new(details, [new("one", view)], historyBudget), ct);
try
{
Check(first.Count == 1 && first[0].CorrelationId == "one", "history cardinality");
pages.Add(Page(first[0]));
if (command.ExpectedState == "Unsupported")
{
Check(first[0].StatusCode == 0x80720000u && first[0].Samples.Count == 0 && first[0].Continuation is null, "history unsupported");
}
else
{
Check(first[0].StatusCode >> 30 == 0, "history status Good");
Check(first[0].Samples.Count > 0 && (command.HistoryNumValues == 0 || first[0].Samples.Count <= command.HistoryNumValues), "history page bound");
if (command.HistoryStartUtc is null)
Check(first[0].Samples.Zip(first[0].Samples.Skip(1)).All(pair => pair.First.SourceTimestampUtc > pair.Second.SourceTimestampUtc), "end-only read newest first");
if (first[0].Continuation is { } token)
{
var second = await history.ReadAsync(new(details, [new("one", view, null, token)], historyBudget), ct);
try
{
Check(second.Count == 1, "resumed cardinality");
pages.Add(Page(second[0]));
Check(second[0].StatusCode >> 30 == 0 && second[0].Samples.Count > 0, "resumed page Good");
if (command.HistoryStartUtc is null)
Check(second[0].Samples[0].SourceTimestampUtc < first[0].Samples[^1].SourceTimestampUtc, "resumed page continues older");
if (second[0].Continuation is { } rest) await history.ReleaseAsync([rest], ct);
}
finally { foreach (var item in second) item.Dispose(); }
}
}
}
finally { foreach (var item in first) item.Dispose(); }
}
else throw new InvalidOperationException("unsupported operation");
return new(command.Id, command.Operation, true, assertions, observations);
}