Mass passes need to say what they do now (photo x of y, sequence n of m) without slowing down. This adds the contract and the engine side; handlers and displays follow in their own parcels. - Core: JobDetail (step, item, item x of y, part n of m with unit), JobStep and JobPartUnit appended-only and stored by kebab name; Job.Detail. - Protocol: JobDetailDto, appended as JobDto.Detail, JobProgressEvent.Detail and NodeProgress.Detail, so older peers ignore it and newer ones fall back. - Data: JobContext keeps a detail across reports (ReportAsync with a detail, ReportItemAsync without allocating, CheckpointAsync with a detail) and publishes at most once per ProgressInterval (500 ms on the engine's TimeProvider), at once for the first report, a new step or a completed count; a dropped report costs no allocation or lock, and the persist that falls due publishes what it saves. Persist stays at most every 5 s. JobWire maps steps, units and details; an unknown name reads as none. - Migration 0011 adds jobs.progress_detail (nullable JSON text); an unreadable cell reads as no detail. Lists return it. - Server: ProgressGate (500 ms per job, step-change and completion bypass) shared by the engine host and render nodes; node details are stored and broadcast, an older node without one still works. Refs #65 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
102 lines
4.8 KiB
C#
102 lines
4.8 KiB
C#
using Chronos.Core.Model;
|
|
using Chronos.Data.Jobs;
|
|
using Chronos.Protocol;
|
|
using Chronos.Testing;
|
|
|
|
namespace Chronos.Data.Tests.Jobs;
|
|
|
|
/// <summary>The names the jobs' kinds carry on the wire and in settings (BRIEF §14.6): stable once shipped.</summary>
|
|
[Category("jobs")]
|
|
public sealed class JobWireTests
|
|
{
|
|
[Theory]
|
|
[Case(JobKind.WorkspaceCopy, 20, "workspace-copy")]
|
|
[Case(JobKind.WorkspaceRender, 21, "workspace-render")]
|
|
[Case(JobKind.WorkspaceSend, 22, "workspace-send")]
|
|
[Case(JobKind.WorkspaceMove, 23, "workspace-move")]
|
|
[Case(JobKind.VideoCopy, 24, "video-copy")]
|
|
public void TheWorkspaceJobsKeepTheirValueAndName(JobKind kind, int value, string name)
|
|
{
|
|
Assert.Equal(value, (int)kind);
|
|
Assert.Equal(name, JobWire.Kind(kind));
|
|
Assert.True(JobWire.TryParseKind(name, out var parsed), name);
|
|
Assert.Equal(kind, parsed);
|
|
}
|
|
|
|
[Test]
|
|
public void EveryKindHasItsOwnName()
|
|
{
|
|
var names = Enum.GetValues<JobKind>().Select(JobWire.Kind).ToList();
|
|
Assert.Equal(names.Count, names.Distinct(StringComparer.Ordinal).Count());
|
|
Assert.False(JobWire.TryParseKind("workspace-teleport", out _));
|
|
}
|
|
|
|
/// <summary>Steps and units are stored and sent by name, appended only: these values and names are pinned once shipped.</summary>
|
|
[Theory]
|
|
[Case(JobStep.None, 0, "none")]
|
|
[Case(JobStep.List, 1, "list")]
|
|
[Case(JobStep.Verify, 4, "verify")]
|
|
[Case(JobStep.CopyPhoto, 11, "copy-photo")]
|
|
[Case(JobStep.CopyOriginal, 13, "copy-original")]
|
|
[Case(JobStep.FollowUps, 22, "follow-ups")]
|
|
[Case(JobStep.Process, 23, "process")]
|
|
public void StepsKeepTheirValueAndName(JobStep step, int value, string name)
|
|
{
|
|
Assert.Equal(value, (int)step);
|
|
Assert.Equal(name, JobWire.Step(step));
|
|
Assert.True(JobWire.TryParseStep(name, out var parsed), name);
|
|
Assert.Equal(step, parsed);
|
|
}
|
|
|
|
[Test]
|
|
public void EveryStepAndUnitHasItsOwnName()
|
|
{
|
|
var steps = Enum.GetValues<JobStep>().Select(JobWire.Step).ToList();
|
|
Assert.Equal(steps.Count, steps.Distinct(StringComparer.Ordinal).Count());
|
|
Assert.SequenceEqual(["none", "sequence", "folder", "render", "entry", "step"], Enum.GetValues<JobPartUnit>().Select(JobWire.PartUnit));
|
|
Assert.False(JobWire.TryParseStep("teleport", out _));
|
|
Assert.False(JobWire.TryParsePartUnit(null, out _));
|
|
}
|
|
|
|
[Test]
|
|
public void ADetailCrossesTheWireAndBack()
|
|
{
|
|
var detail = new JobDetail(JobStep.CopyOriginal, "2024/2024-09-27 Harbour sunset", 1240, 3600, 12, 340, JobPartUnit.Folder);
|
|
var dto = JobWire.Detail(detail)!;
|
|
Assert.Equal(new JobDetailDto("copy-original", "2024/2024-09-27 Harbour sunset", 1240, 3600, 12, 340, "folder"), dto);
|
|
Assert.Equal(detail, JobWire.FromDto(dto));
|
|
// A unit of none is left out; nothing is none.
|
|
Assert.Null(JobWire.Detail(new JobDetail(JobStep.Backup))!.PartUnit);
|
|
Assert.Null(JobWire.Detail(null));
|
|
Assert.Null(JobWire.FromDto((JobDetailDto?)null));
|
|
|
|
// A newer peer's step or unit reads as none and its counts stay; nonsense counts read as 0.
|
|
Assert.Equal(new JobDetail(JobStep.None, "x", 0, 9, 2, 0), JobWire.FromDto(new JobDetailDto("teleport", "x", -4, 9, 2, -1, "galaxy")));
|
|
Assert.Equal(new JobDetail(JobStep.None), JobWire.FromDto(new JobDetailDto(null!)));
|
|
}
|
|
|
|
[Test]
|
|
public void AnItemIsCutToItsLongestLengthWithoutSplittingACharacter()
|
|
{
|
|
var plain = new string('a', JobDetail.MaxItemLength + 40);
|
|
Assert.Equal(JobDetail.MaxItemLength, new JobDetail(JobStep.Index, plain).Item!.Length);
|
|
// A pair whose high half would be the last kept character goes whole.
|
|
var emoji = new string('a', JobDetail.MaxItemLength - 1) + "\U0001F4F7" + "tail";
|
|
var cut = new JobDetail(JobStep.Index, emoji).Item!;
|
|
Assert.Equal(JobDetail.MaxItemLength - 1, cut.Length);
|
|
Assert.False(char.IsHighSurrogate(cut[^1]));
|
|
Assert.Equal(JobDetail.MaxItemLength, (new JobDetail(JobStep.Index) with { Item = plain }).Item!.Length);
|
|
Assert.Equal(JobDetail.MaxItemLength, JobWire.FromDto(new JobDetailDto("index", plain))!.Item!.Length);
|
|
Assert.Equal("short", new JobDetail(JobStep.Index, "short").Item);
|
|
}
|
|
|
|
[Test]
|
|
public void AServerJobBringsItsDetail()
|
|
{
|
|
var dto = new JobDto(Guid.NewGuid(), "verify", [], "Archive", "paused", "normal", 4, 10, null, null, null, null, 1, null, DateTimeOffset.UtcNow, null, null,
|
|
Detail: new JobDetailDto("verify", "Harbour sunset", 812, 2400, 3, 41, "sequence"));
|
|
Assert.Equal(new JobDetail(JobStep.Verify, "Harbour sunset", 812, 2400, 3, 41, JobPartUnit.Sequence), JobWire.FromDto(dto)!.Detail);
|
|
Assert.Null(JobWire.FromDto(dto with { Detail = null })!.Detail);
|
|
}
|
|
}
|