test(grpc-data): A2b smoke — conditions profile grants the method bits; probe remote ack (+ duplicate, header-less, Secondary); origin CLI alarms watcher counts exactly one ack

This commit is contained in:
Joseph Doherty
2026-11-24 13:55:45 -05:00
parent e29d9559ad
commit d63884e624
3 changed files with 81 additions and 10 deletions
+49 -8
View File
@@ -307,6 +307,29 @@ try
var complete = false;
var frames = new List<string>();
var flipped = false;
// A2b: on the Primary, a remote Acknowledge of the active alarm (once the snapshot is complete), a duplicate of the
// same operation id (joins), and the same call without the header (FAILED_PRECONDITION); on the Secondary the
// call is RejectedBeforeDispatch (Primary-only).
object? ackEvidence = null;
var acked = false;
var ackSent = false;
async Task<object> RemoteAck(W.View placement, W.ActivationMarker marker)
{
var request = new W.ConditionMethodRequest
{
OperationId = "a2b-ack-" + name, Placement = placement, Method = 1,
ExpectedActivation = marker, Comment = "A2b remote ack",
ExpectedServingIncarnation = featured.Serving.Incarnation, RemainingBudgetTicks = TimeSpan.FromSeconds(10).Ticks,
OnBehalfOf = "probe\u0007operator",
};
var first = await client.CallConditionMethodAsync(request, With(true), DateTime.UtcNow.AddSeconds(15));
var again = await client.CallConditionMethodAsync(request, With(true), DateTime.UtcNow.AddSeconds(15));
string? headerless;
try { await client.CallConditionMethodAsync(request, With(false), DateTime.UtcNow.AddSeconds(15)); headerless = "OK"; }
catch (RpcException ex) { headerless = ex.StatusCode.ToString(); }
return new { first = new { first.State, first.StatusCode, first.Diagnostic }, duplicate = new { again.State, again.StatusCode },
duplicateEqual = first.Equals(again), headerless, firstState = first.State };
}
while (await call.ResponseStream.MoveNext(cts.Token))
{
var frame = call.ResponseStream.Current;
@@ -318,22 +341,40 @@ try
if (states.HasTotal) { total = states.Total; snapshot.Clear(); }
snapshot.AddRange(states.Items);
complete = states.SnapshotComplete;
if (complete && !flipped)
if (complete && !ackSent && snapshot.FirstOrDefault(r => r.Active && r.Info is not null) is { } target)
{
// The alarm was raised (scalar 150) before the stream opened; clear it now and wait for the delta.
flipped = true;
await SetScalar(0);
ackSent = true;
ackEvidence = await RemoteAck(target.Info.Placements[0], target.Activation);
}
continue;
}
deltas.AddRange(states.Items);
if (deltas.Any(r => !r.Active && r.StateKnown)) break;
if (!acked && deltas.Any(r => r.Active && r.Acknowledged && r.StateKnown))
{
// The stream carried the acked delta; now clear the alarm (scalar := 0) and wait for the inactive delta.
acked = true;
flipped = true;
await SetScalar(0);
continue;
}
if (acked && deltas.Any(r => !r.Active && r.StateKnown)) break;
}
await cts.CancelAsync();
// The Secondary never streams (ack Unavailable): its call is refused at the Primary check, before placement lookup.
if (!primary && ackEvidence is null)
ackEvidence = await RemoteAck(equipmentView, new W.ActivationMarker { Incarnation = "none", Sequence = 0 });
var leaked = snapshot.Concat(deltas).Any(r => Record(r).ToString()!.Contains("modbus/plc", StringComparison.Ordinal));
var passed = capsOk && (primary
var ackJson = JsonSerializer.SerializeToElement(ackEvidence);
var methodState = ackEvidence is null ? -1 : ackJson.GetProperty("firstState").GetInt32();
var methodsOk = (featured.Operations & 384) == 384 && (plain.Operations & 384) == 0 && ackEvidence is not null
&& ackJson.GetProperty("headerless").GetString() == "FailedPrecondition"
&& (primary
? methodState == 4 && ackJson.GetProperty("duplicateEqual").GetBoolean()
&& deltas.Count(r => r.Active && r.Acknowledged) == 1
: methodState == 1);
var passed = capsOk && methodsOk && (primary
? ackStatus == 1 && total >= 1 && complete && snapshot.Count == total && snapshot.Any(r => r.Active && r.StateKnown)
&& deltas.Any(r => !r.Active && r.StateKnown) && !leaked
&& acked && deltas.Any(r => !r.Active && r.StateKnown) && !leaked
: ackStatus == 6);
results.Add(new("conditions-" + name, "conditions", passed, primary ? 7 : 2, new()
{
@@ -342,7 +383,7 @@ try
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,
["frames"] = frames, ["rawPathLeaked"] = leaked, ["remoteAck"] = ackEvidence,
}));
if (primary && flipped) await SetScalar(150); // restore for the other node
}