test(grpc-data): A2a — rig --conditions overlay (AlarmSubscribe exports + ScalarHigh scripted alarm), probe conditions scenario, conditions_smoke.py; X0/H2 tests move the 'future' bit off 64
This commit is contained in:
@@ -26,7 +26,7 @@ try
|
||||
using var manifest = JsonDocument.Parse(await File.ReadAllTextAsync(manifestPath));
|
||||
var root = manifest.RootElement;
|
||||
var scenario = arguments.GetValueOrDefault("--scenario", "all");
|
||||
if (scenario is not ("all" or "D13" or "wire" or "history")) throw new ArgumentException("Unsupported wire scenario.");
|
||||
if (scenario is not ("all" or "D13" or "wire" or "history" or "conditions")) throw new ArgumentException("Unsupported wire scenario.");
|
||||
var nodes = root.GetProperty("nodes");
|
||||
var endpoints = root.GetProperty("endpoints");
|
||||
var keyPath = root.GetProperty("credentials").GetProperty("data_key_files").GetProperty("source").GetString()!;
|
||||
@@ -251,7 +251,101 @@ try
|
||||
}
|
||||
}
|
||||
}
|
||||
if (scenario is not ("D13" or "history"))
|
||||
if (scenario == "conditions")
|
||||
{
|
||||
// A2a smoke (opt-in conditions fixture): a root-scoped condition item on each SOURCE listener's UNS equipment root.
|
||||
failurePhase = ProbeFailurePhase.WireOperation;
|
||||
var unsUri = root.GetProperty("fixture").GetProperty("namespace_uris").GetProperty("uns").GetString()!;
|
||||
var equipmentPath = arguments.GetValueOrDefault("--equipment", "area/line/plc");
|
||||
var deviceUrl = endpoints.GetProperty("device.control").GetProperty("url").GetString()!;
|
||||
using var http = new HttpClient();
|
||||
async Task SetScalar(int value)
|
||||
{
|
||||
using var response = await http.PostAsync(deviceUrl + "/control", new StringContent(
|
||||
JsonSerializer.Serialize(new { action = "set", address = 20, value }), System.Text.Encoding.UTF8, "application/json"));
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
var equipmentView = new W.View { Address = new() { OriginClusterId = "SOURCE", NamespaceUri = unsUri, IdentifierKind = "string",
|
||||
Identifier = equipmentPath }, Realm = (int)DataRealm.Uns, Subject = equipmentPath };
|
||||
static object Record(W.ConditionState r) => new
|
||||
{
|
||||
key = r.ConditionKey, r.Version, r.Removed, r.StateKnown, r.Active, r.Acknowledged, r.Severity, r.Message,
|
||||
info = r.Info is null ? null : new { r.Info.ConditionType, r.Info.ConditionName, r.Info.SourceKind,
|
||||
placements = r.Info.Placements.Select(p => p.Address.NamespaceUri + "|" + p.Address.Identifier).ToArray() },
|
||||
};
|
||||
foreach (var node in sourceNodes)
|
||||
{
|
||||
var name = node.Name;
|
||||
failureTarget = name;
|
||||
var nodeId = node.Value.GetProperty("node_id").GetString()!;
|
||||
Metadata With(bool feature)
|
||||
{
|
||||
var headers = Headers(key, "Node", nodeId);
|
||||
if (feature) headers.Add("x-otopcua-data-features", "conditions");
|
||||
return headers;
|
||||
}
|
||||
using var handler = security.Handler(name);
|
||||
using var channel = GrpcChannel.ForAddress($"https://{name}:4057", new() { HttpHandler = handler });
|
||||
var client = new W.DataConnectionService.DataConnectionServiceClient(channel);
|
||||
var plain = await client.GetCapabilitiesAsync(new() { ProtocolMajor = 1, ProtocolMinor = 3 }, With(false), DateTime.UtcNow.AddSeconds(20));
|
||||
var featured = await client.GetCapabilitiesAsync(new() { ProtocolMajor = 1, ProtocolMinor = 3 }, With(true), DateTime.UtcNow.AddSeconds(20));
|
||||
var capsOk = plain.Conditions is null && (plain.Operations & 64) == 0 && featured.Conditions is not null && (featured.Operations & 64) == 64;
|
||||
var primary = featured.Serving.Role == "Primary";
|
||||
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(90));
|
||||
using var call = client.Subscribe(With(true), cancellationToken: cts.Token);
|
||||
var open = new W.SubscriptionCommand { SubscriptionId = "conditions-" + name, StreamEpoch = 1, CommandId = "open-1",
|
||||
AcknowledgementTimeoutTicks = TimeSpan.FromSeconds(10).Ticks, Open = new() { SessionLifetimeTicks = TimeSpan.FromMinutes(5).Ticks,
|
||||
SnapshotBudget = new() { TimeoutTicks = TimeSpan.FromSeconds(20).Ticks, MaxItems = 8, MaxBytes = 4 * 1024 * 1024 } } };
|
||||
open.Open.Items.Add(new W.SubscriptionItem { ClientItemId = "conditions", View = equipmentView,
|
||||
Settings = new() { Trigger = 2 }, ConditionScope = new() { IncludeInfo = true } });
|
||||
await call.RequestStream.WriteAsync(open);
|
||||
int? ackStatus = null, total = null;
|
||||
var snapshot = new List<W.ConditionState>();
|
||||
var deltas = new List<W.ConditionState>();
|
||||
var complete = false;
|
||||
var frames = new List<string>();
|
||||
var flipped = false;
|
||||
while (await call.ResponseStream.MoveNext(cts.Token))
|
||||
{
|
||||
var frame = call.ResponseStream.Current;
|
||||
frames.Add(frame.FrameCase.ToString());
|
||||
if (frame.Ack is { } ack) { ackStatus = ack.Items.Single().Status; if (ackStatus != 1) break; continue; }
|
||||
if (frame.ConditionStates is not { } states) continue;
|
||||
if (states.IsSnapshot)
|
||||
{
|
||||
if (states.HasTotal) { total = states.Total; snapshot.Clear(); }
|
||||
snapshot.AddRange(states.Items);
|
||||
complete = states.SnapshotComplete;
|
||||
if (complete && !flipped)
|
||||
{
|
||||
// The alarm was raised (scalar 150) before the stream opened; clear it now and wait for the delta.
|
||||
flipped = true;
|
||||
await SetScalar(0);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
deltas.AddRange(states.Items);
|
||||
if (deltas.Any(r => !r.Active && r.StateKnown)) break;
|
||||
}
|
||||
await cts.CancelAsync();
|
||||
var leaked = snapshot.Concat(deltas).Any(r => Record(r).ToString()!.Contains("modbus/plc", StringComparison.Ordinal));
|
||||
var passed = capsOk && (primary
|
||||
? ackStatus == 1 && total >= 1 && complete && snapshot.Count == total && snapshot.Any(r => r.Active && r.StateKnown)
|
||||
&& deltas.Any(r => !r.Active && r.StateKnown) && !leaked
|
||||
: ackStatus == 6);
|
||||
results.Add(new("conditions-" + name, "conditions", passed, primary ? 7 : 2, new()
|
||||
{
|
||||
["role"] = featured.Serving.Role,
|
||||
["capabilities"] = new { withoutHeader = new { operations = plain.Operations, conditions = plain.Conditions?.ToString() },
|
||||
withHeader = new { operations = featured.Operations, conditions = featured.Conditions?.ToString() } },
|
||||
["ackStatus"] = ackStatus, ["total"] = total, ["snapshotComplete"] = complete,
|
||||
["snapshot"] = snapshot.Select(Record).ToArray(), ["deltas"] = deltas.Select(Record).ToArray(),
|
||||
["frames"] = frames, ["rawPathLeaked"] = leaked,
|
||||
}));
|
||||
if (primary && flipped) await SetScalar(150); // restore for the other node
|
||||
}
|
||||
}
|
||||
if (scenario is not ("D13" or "history" or "conditions"))
|
||||
{
|
||||
var fixture = root.GetProperty("fixture");
|
||||
var rawUri = fixture.GetProperty("namespace_uris").GetProperty("raw").GetString()!;
|
||||
|
||||
Reference in New Issue
Block a user