feat: single setup, mass-pass progress, per-server homes, Desktop shares its library (owner review 5, v1.1.0) (#68)
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
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>
This commit was merged in pull request #68.
This commit is contained in:
1 parent
988068ee8e
commit
20d64af4a4
793 files changed
+23882
-2096
No files matched your search
@@ -0,0 +1,62 @@
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Data.Jobs;
|
||||
|
||||
namespace Chronos.Data.Tests.Jobs;
|
||||
|
||||
/// <summary>
|
||||
/// Every progress report a job engine publishes, kept to tell which details a handler sent and in what order (owner review
|
||||
/// 5, #65). The engine it records has no publish throttle (<see cref="Options"/>), so each report a handler makes goes out.
|
||||
/// </summary>
|
||||
internal sealed class DetailRecorder
|
||||
{
|
||||
private readonly List<JobProgressInfo> _published = [];
|
||||
|
||||
/// <summary>A started engine's options that publish every report: one worker, fast polls and checkpoints, no progress interval.</summary>
|
||||
public static JobEngineOptions Options(string worker = "detail") => new()
|
||||
{
|
||||
Workers = 1,
|
||||
WorkerId = worker,
|
||||
PollInterval = TimeSpan.FromMilliseconds(50),
|
||||
CheckpointInterval = TimeSpan.FromMilliseconds(50),
|
||||
ProgressInterval = TimeSpan.Zero,
|
||||
};
|
||||
|
||||
/// <summary>A new engine with <paramref name="handlers"/>, recorded, not started.</summary>
|
||||
public JobEngine Engine(ChronosDatabase db, IEnumerable<IJobHandler> handlers, string worker = "detail")
|
||||
{
|
||||
var engine = new JobEngine(db, [.. handlers], Options(worker));
|
||||
engine.Progress += p =>
|
||||
{
|
||||
lock (_published) _published.Add(p);
|
||||
};
|
||||
return engine;
|
||||
}
|
||||
|
||||
/// <summary>The reports of <paramref name="jobId"/> in the order they went out.</summary>
|
||||
public IReadOnlyList<JobProgressInfo> Of(Guid jobId)
|
||||
{
|
||||
lock (_published) return [.. _published.Where(p => p.JobId == jobId)];
|
||||
}
|
||||
|
||||
/// <summary>The details of <paramref name="jobId"/>, without repeats of the one before.</summary>
|
||||
public IReadOnlyList<JobDetail> Details(Guid jobId)
|
||||
{
|
||||
var details = new List<JobDetail>();
|
||||
foreach (var report in Of(jobId))
|
||||
{
|
||||
if (report.Detail is { } detail && (details.Count == 0 || details[^1] != detail)) details.Add(detail);
|
||||
}
|
||||
return details;
|
||||
}
|
||||
|
||||
/// <summary>The steps of <paramref name="jobId"/> in order, each once in a row.</summary>
|
||||
public IReadOnlyList<JobStep> Steps(Guid jobId)
|
||||
{
|
||||
var steps = new List<JobStep>();
|
||||
foreach (var detail in Details(jobId))
|
||||
{
|
||||
if (steps.Count == 0 || steps[^1] != detail.Step) steps.Add(detail.Step);
|
||||
}
|
||||
return steps;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,267 @@
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Data.Jobs;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.Data.Tests.Jobs;
|
||||
|
||||
/// <summary>
|
||||
/// How a running job's progress goes out (owner review 5, #65): at most twice a second, at once for the run's first report,
|
||||
/// a new step and a completed count, and with the persist that falls due when the last report was dropped; saved at most
|
||||
/// every checkpoint interval and at each checkpoint, with its detail.
|
||||
/// </summary>
|
||||
[Category("jobs")]
|
||||
public sealed class JobContextProgressTests(TestContext context)
|
||||
{
|
||||
private static readonly TimeSpan Tick = TimeSpan.FromMilliseconds(10);
|
||||
|
||||
/// <summary>A quarter of the default publish interval: what a new step waits since the last publish.</summary>
|
||||
private static readonly TimeSpan StepWait = TimeSpan.FromMilliseconds(125);
|
||||
|
||||
[Test]
|
||||
public async Task AHundredReportsInASecondGoOutAtMostThreeTimes()
|
||||
{
|
||||
await using var run = await StartAsync();
|
||||
for (var i = 1; i <= 100; i++)
|
||||
{
|
||||
await run.Context.ReportAsync(i, 1000);
|
||||
run.Time.Advance(Tick);
|
||||
}
|
||||
Assert.True(run.Published.Count <= 3, $"{run.Published.Count} publishes");
|
||||
// The first at once, then one per half second: the latest state when its time comes.
|
||||
Assert.SequenceEqual([1L, 50L, 100L], run.Published.Select(p => p.Done));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AJobGoneQuietInALongStepShowsItsLatestStateOnTime()
|
||||
{
|
||||
await using var run = await StartAsync();
|
||||
// Maintenance: its first sub-steps take milliseconds, the third runs for minutes without a report.
|
||||
await run.Context.ReportAsync(0, 5, new JobDetail(JobStep.Maintenance, "leases", 0, 0, 1, 5, JobPartUnit.Step));
|
||||
run.Time.Advance(TimeSpan.FromMilliseconds(30));
|
||||
await run.Context.CheckpointAsync("leases", 1, 5, new JobDetail(JobStep.Maintenance, "temp", 0, 0, 2, 5, JobPartUnit.Step));
|
||||
run.Time.Advance(TimeSpan.FromMilliseconds(30));
|
||||
var packs = new JobDetail(JobStep.Maintenance, "packs", 0, 0, 3, 5, JobPartUnit.Step);
|
||||
await run.Context.CheckpointAsync("temp", 2, 5, packs);
|
||||
Assert.Count(1, run.Published);
|
||||
|
||||
run.Time.Advance(TimeSpan.FromMilliseconds(500));
|
||||
Assert.Count(2, run.Published);
|
||||
Assert.Equal((2L, packs), (run.Published[^1].Done, run.Published[^1].Detail));
|
||||
// Nothing new: nothing more goes out.
|
||||
run.Time.Advance(TimeSpan.FromSeconds(10));
|
||||
Assert.Count(2, run.Published);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AJobThatAlternatesStepsGoesOutAFewTimesASecond()
|
||||
{
|
||||
await using var run = await StartAsync();
|
||||
// An incremental scan: every other folder changed, checked and indexed in turn, 200 reports in a second.
|
||||
for (var i = 0; i < 200; i++)
|
||||
{
|
||||
var step = i % 2 == 0 ? JobStep.Check : JobStep.Index;
|
||||
await run.Context.ReportAsync(i, 10_000, new JobDetail(step, "folder " + i, 0, 0, i + 1, 10_000, JobPartUnit.Folder));
|
||||
run.Time.Advance(TimeSpan.FromMilliseconds(5));
|
||||
}
|
||||
Assert.True(run.Published.Count <= 10, $"{run.Published.Count} publishes");
|
||||
// The last report still goes out once its time comes.
|
||||
run.Time.Advance(TimeSpan.FromSeconds(1));
|
||||
Assert.Equal(199L, run.Published[^1].Done);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ANewStepAndACompletedCountGoOutAtOnce()
|
||||
{
|
||||
await using var run = await StartAsync();
|
||||
var index = new JobDetail(JobStep.Index, "2024/Harbour sunset", 1, 5, 1, 2, JobPartUnit.Folder);
|
||||
await run.Context.ReportAsync(1, 10, new JobDetail(JobStep.List));
|
||||
run.Time.Advance(Tick);
|
||||
await run.Context.ReportAsync(2, 10, new JobDetail(JobStep.List));
|
||||
// A new step goes out once a quarter of the interval has passed, not at every switch.
|
||||
run.Time.Advance(StepWait);
|
||||
await run.Context.ReportAsync(3, 10, index);
|
||||
run.Time.Advance(Tick);
|
||||
await run.Context.ReportItemAsync(4, 10, 2, 5);
|
||||
run.Time.Advance(Tick);
|
||||
await run.Context.ReportAsync(10, 10);
|
||||
run.Time.Advance(Tick);
|
||||
await run.Context.ReportAsync(10, 10);
|
||||
|
||||
Assert.SequenceEqual([1L, 3L, 10L], run.Published.Select(p => p.Done));
|
||||
Assert.Equal(index, run.Published[1].Detail);
|
||||
// A report without a detail keeps the last one, with the item counts reported since.
|
||||
Assert.Equal(index with { ItemDone = 2 }, run.Published[2].Detail);
|
||||
Assert.Equal(index with { ItemDone = 2 }, run.Context.Detail);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ADroppedReportGoesOutWithThePersistThatFallsDue()
|
||||
{
|
||||
await using var run = await StartAsync();
|
||||
await run.Context.ReportAsync(1, 100);
|
||||
run.Time.Advance(TimeSpan.FromSeconds(4.8));
|
||||
await run.Context.ReportAsync(2, 100);
|
||||
Assert.Equal(0L, (await run.StoredAsync()).ProgressDone);
|
||||
run.Time.Advance(TimeSpan.FromSeconds(0.2));
|
||||
// Too soon for a publish, but the persist falls due: it shows what it saves.
|
||||
await run.Context.ReportAsync(3, 100);
|
||||
Assert.SequenceEqual([1L, 2L, 3L], run.Published.Select(p => p.Done));
|
||||
Assert.Equal(3L, (await run.StoredAsync()).ProgressDone);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ProgressIsSavedAtMostEveryCheckpointIntervalAndAtEachCheckpoint()
|
||||
{
|
||||
await using var run = await StartAsync();
|
||||
for (var i = 1; i <= 50; i++)
|
||||
{
|
||||
await run.Context.ReportAsync(i, 100);
|
||||
run.Time.Advance(TimeSpan.FromMilliseconds(99));
|
||||
}
|
||||
Assert.Equal(0L, (await run.StoredAsync()).ProgressDone);
|
||||
run.Time.Advance(TimeSpan.FromMilliseconds(50));
|
||||
await run.Context.ReportAsync(51, 100);
|
||||
Assert.Equal(51L, (await run.StoredAsync()).ProgressDone);
|
||||
var published = run.Published.Count;
|
||||
|
||||
// A checkpoint is saved at once; it goes out as any report would.
|
||||
run.Time.Advance(Tick);
|
||||
await run.Context.CheckpointAsync("52", 52, 100);
|
||||
var stored = await run.StoredAsync();
|
||||
Assert.Equal((52L, "52"), (stored.ProgressDone, stored.Checkpoint));
|
||||
Assert.Null(stored.Detail);
|
||||
Assert.Equal(published, run.Published.Count);
|
||||
|
||||
var verify = new JobDetail(JobStep.Verify, "Harbour sunset", 1, 9, 1, 3, JobPartUnit.Sequence);
|
||||
run.Time.Advance(StepWait);
|
||||
await run.Context.CheckpointAsync("53", 53, 100, verify);
|
||||
stored = await run.StoredAsync();
|
||||
Assert.Equal((53L, "53", verify), (stored.ProgressDone, stored.Checkpoint, stored.Detail));
|
||||
Assert.Equal(verify, run.Published[^1].Detail);
|
||||
|
||||
// A checkpoint without a detail keeps it.
|
||||
run.Time.Advance(Tick);
|
||||
await run.Context.CheckpointAsync("54", 54, 100);
|
||||
Assert.Equal(verify, (await run.StoredAsync()).Detail);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheRateIsTheSameUnderThePublishThrottle()
|
||||
{
|
||||
await using var run = await StartAsync();
|
||||
// 100 photos a second for ten seconds, every photo reported.
|
||||
for (var i = 1; i <= 1000; i++)
|
||||
{
|
||||
await run.Context.ReportAsync(i, 2000);
|
||||
run.Time.Advance(Tick);
|
||||
}
|
||||
Assert.True(run.Published.Count <= 22, $"{run.Published.Count} publishes");
|
||||
var last = run.Published[^1];
|
||||
Assert.Approximately(100, last.ItemsPerSecond!.Value, 0.5);
|
||||
Assert.Approximately((2000 - last.Done) / 100.0, last.Eta!.Value.TotalSeconds, 0.1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ItemCountsWithoutADetailAreAPhotoPass()
|
||||
{
|
||||
await using var run = await StartAsync();
|
||||
Assert.Null(run.Context.Detail);
|
||||
await run.Context.ReportItemAsync(1, 10, 3, 9);
|
||||
Assert.Equal(new JobDetail(JobStep.Process, null, 3, 9), run.Context.Detail);
|
||||
Assert.Equal(run.Context.Detail, run.Published.Single().Detail);
|
||||
// A plain report keeps the detail and drops the old free text.
|
||||
await run.Context.ReportAsync(2, 10, "IMG_0001.CR3");
|
||||
await run.Context.ReportAsync(3, 10);
|
||||
Assert.Null(run.Context.Message);
|
||||
Assert.Equal(new JobDetail(JobStep.Process, null, 3, 9), run.Context.Detail);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ADroppedReportAllocatesNothing()
|
||||
{
|
||||
await using var run = await StartAsync();
|
||||
var thumbs = new JobDetail(JobStep.Thumbs, "Harbour sunset", 0, 3600, 2, 7, JobPartUnit.Sequence);
|
||||
await run.Context.ReportAsync(1, 1_000_000, thumbs);
|
||||
var job = run.Context;
|
||||
var dropped = 0;
|
||||
for (var i = 0; i < 200; i++) dropped += Drop(job, thumbs, i) ? 1 : 0;
|
||||
var before = GC.GetAllocatedBytesForCurrentThread();
|
||||
for (var i = 0; i < 20_000; i++) dropped += Drop(job, thumbs, i) ? 1 : 0;
|
||||
var allocated = GC.GetAllocatedBytesForCurrentThread() - before;
|
||||
Assert.Equal(20_200, dropped);
|
||||
Assert.Equal(0L, allocated);
|
||||
Assert.Count(1, run.Published);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheEngineSendsAndSavesTheDetail()
|
||||
{
|
||||
await using var db = await ChronosDatabase.OpenAsync(DatabaseOptions.Sqlite(Path.Combine(context.CreateTempDirectory(), "jobs.db")), context.Cancellation);
|
||||
var verify = new JobDetail(JobStep.Verify, "Harbour sunset", 5, 9, 1, 2, JobPartUnit.Sequence);
|
||||
var handler = new CallbackHandler(JobKind.Verify, async c =>
|
||||
{
|
||||
await c.CheckpointAsync("1", 1, 2, verify);
|
||||
await c.ReportAsync(2, 2);
|
||||
});
|
||||
await using var engine = new JobEngine(db, [handler], new JobEngineOptions { Workers = 1, WorkerId = "t" });
|
||||
var published = new List<JobProgressInfo>();
|
||||
engine.Progress += p =>
|
||||
{
|
||||
lock (published) published.Add(p);
|
||||
};
|
||||
await engine.StartAsync(context.Cancellation);
|
||||
var job = await engine.EnqueueAsync(JobKind.Verify, [Guid.NewGuid()], cancellationToken: context.Cancellation);
|
||||
var until = DateTime.UtcNow.AddSeconds(15);
|
||||
Job? done = null;
|
||||
while (DateTime.UtcNow < until && (done = await db.Jobs.GetAsync(job.Id, context.Cancellation))?.State != JobState.Done) await Task.Delay(20, context.Cancellation);
|
||||
Assert.Equal(JobState.Done, done?.State);
|
||||
Assert.Equal(verify, done!.Detail);
|
||||
lock (published) Assert.SequenceEqual([verify, verify], published.Select(p => p.Detail));
|
||||
}
|
||||
|
||||
/// <summary>One report dropped by the throttle: no new step, no completed count, no time passed.</summary>
|
||||
private static bool Drop(JobContext job, JobDetail detail, int i)
|
||||
{
|
||||
var item = job.ReportItemAsync(2 + i, 1_000_000, i, 3600);
|
||||
var full = job.ReportAsync(3 + i, 1_000_000, detail);
|
||||
return item.IsCompletedSuccessfully && full.IsCompletedSuccessfully;
|
||||
}
|
||||
|
||||
private async Task<Run> StartAsync()
|
||||
{
|
||||
var time = new ManualTime();
|
||||
var db = await ChronosDatabase.OpenAsync(DatabaseOptions.Sqlite(Path.Combine(context.CreateTempDirectory(), "jobs.db")), context.Cancellation);
|
||||
var engine = new JobEngine(db, [], new JobEngineOptions { WorkerId = "t", Time = time });
|
||||
var run = new Run(db, engine, time);
|
||||
engine.Progress += run.Published.Add;
|
||||
await db.Jobs.EnqueueAsync(new Job { Id = Guid.CreateVersion7(), Kind = JobKind.Verify, State = JobState.Queued, Created = DateTimeOffset.UtcNow },
|
||||
context.Cancellation);
|
||||
var claimed = Assert.NotNull(await db.Jobs.ClaimNextAsync("t", null, context.Cancellation));
|
||||
run.Context = new JobContext(engine, claimed, context.Cancellation);
|
||||
return run;
|
||||
}
|
||||
|
||||
private sealed class Run(ChronosDatabase db, JobEngine engine, ManualTime time) : IAsyncDisposable
|
||||
{
|
||||
public ManualTime Time { get; } = time;
|
||||
|
||||
public JobContext Context { get; set; } = null!;
|
||||
|
||||
public List<JobProgressInfo> Published { get; } = [];
|
||||
|
||||
public async Task<Job> StoredAsync() => (await db.Jobs.GetAsync(Context.Job.Id))!;
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
await engine.DisposeAsync();
|
||||
await db.DisposeAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class CallbackHandler(JobKind kind, Func<JobContext, Task> run) : IJobHandler
|
||||
{
|
||||
public JobKind Kind => kind;
|
||||
|
||||
public Task RunAsync(JobContext context) => run(context);
|
||||
}
|
||||
}
|
||||
@@ -5,16 +5,71 @@ using Chronos.Testing;
|
||||
|
||||
namespace Chronos.Data.Tests.Jobs;
|
||||
|
||||
/// <summary>A clock the test moves by hand (BCL <see cref="TimeProvider"/>, no package).</summary>
|
||||
/// <summary>
|
||||
/// A clock the test moves by hand (BCL <see cref="TimeProvider"/>, no package), whose timers fire only when
|
||||
/// <see cref="Advance"/> reaches them, on the test's thread.
|
||||
/// </summary>
|
||||
internal sealed class ManualTime : TimeProvider
|
||||
{
|
||||
private readonly Lock _gate = new();
|
||||
private readonly List<Timer> _timers = [];
|
||||
private long _ticks;
|
||||
|
||||
public override long TimestampFrequency => TimeSpan.TicksPerSecond;
|
||||
|
||||
public override long GetTimestamp() => Interlocked.Read(ref _ticks);
|
||||
|
||||
public void Advance(TimeSpan by) => Interlocked.Add(ref _ticks, by.Ticks);
|
||||
public override ITimer CreateTimer(TimerCallback callback, object? state, TimeSpan dueTime, TimeSpan period)
|
||||
{
|
||||
var timer = new Timer(this, callback, state);
|
||||
timer.Change(dueTime, period);
|
||||
return timer;
|
||||
}
|
||||
|
||||
/// <summary>Moves the clock on, then fires each one-shot timer due by then.</summary>
|
||||
public void Advance(TimeSpan by)
|
||||
{
|
||||
List<Timer> due;
|
||||
lock (_gate)
|
||||
{
|
||||
var now = Interlocked.Add(ref _ticks, by.Ticks);
|
||||
due = [.. _timers.Where(t => t.Due <= now)];
|
||||
foreach (var timer in due) _timers.Remove(timer);
|
||||
}
|
||||
foreach (var timer in due) timer.Fire();
|
||||
}
|
||||
|
||||
private void Schedule(Timer timer, TimeSpan dueTime)
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
_timers.Remove(timer);
|
||||
if (dueTime == Timeout.InfiniteTimeSpan) return;
|
||||
timer.Due = Interlocked.Read(ref _ticks) + dueTime.Ticks;
|
||||
_timers.Add(timer);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class Timer(ManualTime clock, TimerCallback callback, object? state) : ITimer
|
||||
{
|
||||
public long Due { get; set; }
|
||||
|
||||
public bool Change(TimeSpan dueTime, TimeSpan period)
|
||||
{
|
||||
clock.Schedule(this, dueTime);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Fire() => callback(state);
|
||||
|
||||
public void Dispose() => clock.Schedule(this, Timeout.InfiniteTimeSpan);
|
||||
|
||||
public ValueTask DisposeAsync()
|
||||
{
|
||||
Dispose();
|
||||
return ValueTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Category("jobs")]
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Data.Jobs;
|
||||
using Chronos.Protocol;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.Data.Tests.Jobs;
|
||||
@@ -29,4 +30,72 @@ public sealed class JobWireTests
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user