Desktop foundation / core (ubuntu-latest) (push) Failing after 28s
Desktop foundation / core (macos-latest) (push) Canceled after 0s
Desktop foundation / core (windows-latest) (push) Canceled after 0s
Linux / verify (push) Canceled after 0s
Linux / keyless-cuda (push) Canceled after 0s
Linux / static-cuda-package (push) Canceled after 0s
Linux / hosted-cuda-package (push) Canceled after 0s
Linux / linux-static-cli (push) Canceled after 0s
Linux / linux-cli-container (push) Canceled after 0s
Linux / release-cli (push) Canceled after 0s
91 lines
5.3 KiB
C#
91 lines
5.3 KiB
C#
using Grpc.Core;
|
|
using Strata.Node.V1;
|
|
|
|
namespace Strata.Desktop;
|
|
|
|
internal static partial class CoreClient
|
|
{
|
|
private sealed class LostAcknowledgementRpc(IWorkerRpc inner) : IWorkerRpc
|
|
{
|
|
public int Submits;
|
|
public Task<WorkerReading> Read(CancellationToken token) => inner.Read(token);
|
|
public Task<WorkerOperation> Lookup(string id, CancellationToken token) => inner.Lookup(id, token);
|
|
public async Task<WorkerOperation> Submit(WorkerCommand command, CancellationToken token)
|
|
{
|
|
Submits++;
|
|
await inner.Submit(command, token);
|
|
throw new RpcException(new Status(StatusCode.Unavailable, "Synthetic lost acknowledgement"));
|
|
}
|
|
}
|
|
private sealed class ChangedEpochRpc(bool durable = false) : IWorkerRpc
|
|
{
|
|
public int Submits;
|
|
public bool Changed;
|
|
public Task<WorkerReading> Read(CancellationToken token) => Task.FromResult(new WorkerReading(
|
|
Changed ? "replacement" : "original", new WorkerState { Phase = "stopped", Model = "synthetic" }, durable));
|
|
public Task<WorkerOperation> Lookup(string id, CancellationToken token) => durable
|
|
? Task.FromResult(new WorkerOperation { OperationId = id, Status = "succeeded" })
|
|
: throw new Exception("Must not query replaced epoch");
|
|
public Task<WorkerOperation> Submit(WorkerCommand command, CancellationToken token) {
|
|
Submits++; Changed = true;
|
|
throw new RpcException(new Status(StatusCode.Unavailable, "Synthetic epoch replacement"));
|
|
}
|
|
}
|
|
public static async Task WorkerSelfCheck()
|
|
{
|
|
if (Environment.GetEnvironmentVariable("STRATA_NODE_ENDPOINT") == null)
|
|
throw new InvalidOperationException("Lifecycle check requires an isolated configured test node.");
|
|
using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(25));
|
|
var token = timeout.Token;
|
|
var rpc = new LostAcknowledgementRpc(WorkerRpc());
|
|
var controller = new WorkerController(rpc);
|
|
await controller.Refresh(token);
|
|
if (!controller.View.CanStart) throw new Exception("Fixture must start stopped");
|
|
await controller.Command(true, token);
|
|
var id = controller.View.OperationId;
|
|
if (id.Length == 0 || controller.View.CanStart || controller.View.CanStop) throw new Exception("Uncertain command must block duplicates");
|
|
while (controller.View.Phase != "ready" || !controller.View.CanStop) {
|
|
await controller.Refresh(token);
|
|
await Task.Delay(50, token);
|
|
}
|
|
if (rpc.Submits != 1) throw new Exception("Mutation was replayed");
|
|
var pid = controller.View.Pid;
|
|
// Closing a desktop client must not stop a configured persistent node.
|
|
Close();
|
|
await controller.Refresh(token);
|
|
if (controller.View.Pid != pid || !controller.View.CanStop) throw new Exception("Worker did not survive client close");
|
|
var c = await Connect(token);
|
|
using (var response = c.Respond(new ResponseRequest { Json = Google.Protobuf.ByteString.CopyFromUtf8(
|
|
"""{"model":"fixture","input":"synthetic","stream":false}""") }, Headers(), cancellationToken: token)) {
|
|
using var bytes = new MemoryStream(); bool ended = false;
|
|
while (await response.ResponseStream.MoveNext(token)) {
|
|
var frame = response.ResponseStream.Current;
|
|
if (frame.PayloadCase == ResponseFrame.PayloadOneofCase.Data) bytes.Write(frame.Data.Span);
|
|
if (frame.PayloadCase == ResponseFrame.PayloadOneofCase.End) ended = true;
|
|
if (frame.PayloadCase == ResponseFrame.PayloadOneofCase.Headers && frame.Headers.Status != 200) throw new Exception("Response failed");
|
|
}
|
|
if (!ended || System.Text.Encoding.UTF8.GetString(bytes.ToArray()) != """{"id":"fixture_response","status":"completed","output":[]}""")
|
|
throw new Exception("Response bytes or terminal changed");
|
|
}
|
|
await controller.Command(false, token);
|
|
while (controller.View.Phase != "stopped" || !controller.View.CanStart) {
|
|
await controller.Refresh(token); await Task.Delay(50, token);
|
|
}
|
|
if (rpc.Submits != 2) throw new Exception("Stop was replayed");
|
|
var changed = new ChangedEpochRpc();
|
|
var epoch = new WorkerController(changed);
|
|
await epoch.Refresh(token); await epoch.Command(true, token); await epoch.Refresh(token);
|
|
await epoch.Command(true, token);
|
|
if (changed.Submits != 1 || epoch.View.CanStart || epoch.View.CanStop || epoch.View.OperationId.Length == 0)
|
|
throw new Exception("Epoch replacement enabled unsafe mutation");
|
|
var journalRpc = new ChangedEpochRpc(true);
|
|
var journalController = new WorkerController(journalRpc);
|
|
await journalController.Refresh(token);
|
|
await journalController.Command(true, token);
|
|
await journalController.Refresh(token);
|
|
if (journalRpc.Submits != 1 || !journalController.View.CanStart || journalController.View.OperationId.Length != 0)
|
|
throw new Exception("Durable completed outcome did not reconcile without replay");
|
|
Console.WriteLine("PASS: desktop lifecycle start/stop, lost-ack reconciliation, no duplicate mutation, client-close independence, epoch replacement blocked, byte-exact synthetic Responses.");
|
|
}
|
|
}
|