CI / Build and test (push) Successful in 11m36s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 12s
Release / Build, test and publish (push) Successful in 14m56s
CI / PostgreSQL 16 integration (push) Successful in 10m11s
CI / PostgreSQL 17 integration (push) Successful in 10m15s
CI / Docker image (push) Successful in 45s
Release / Server image (push) Successful in 4m55s
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.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);
|
|
}
|
|
}
|