CI / Build and test (push) Successful in 10m37s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 9s
Release / Build, test and publish (push) Successful in 16m19s
CI / PostgreSQL 16 integration (push) Successful in 10m19s
CI / PostgreSQL 17 integration (push) Successful in 11m27s
CI / Docker image (push) Successful in 57s
Release / Server image (push) Successful in 1m34s
Owner review 4 and owner review 1 phase 6. - Work board in Videos (desktop and admin panel): Published and Workspace lanes (#29). - Anonymous usage counts removed: Chronos sends nothing about its use (#30). - The archive's whole folder tree is created inside any archive root, on the server and the desktop (#31). - Video cards start with the preset; sizes keep number and unit together (#28). - Deploy guide docs/deploy (Docker, Unraid, desktop), BRIEF §24, original documentation in docs/reference/original (#22). Closes #22 #28 #29 #30 #31 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
234 lines
11 KiB
C#
234 lines
11 KiB
C#
using System.Globalization;
|
|
using Chronos.App.Infrastructure;
|
|
using Chronos.App.Jobs;
|
|
using Chronos.Core.Localization;
|
|
using Chronos.Core.Model;
|
|
using Chronos.Data.Jobs;
|
|
using Chronos.Testing;
|
|
|
|
namespace Chronos.App.Tests.Jobs;
|
|
|
|
public sealed class JobListModelTests
|
|
{
|
|
private static readonly DateTimeOffset T0 = new(2026, 9, 28, 10, 0, 0, TimeSpan.Zero);
|
|
|
|
[Test]
|
|
public void OrderIsRunningPausedQueueThenNewestHistory()
|
|
{
|
|
var model = new JobListModel();
|
|
var oldDone = Job(JobState.Done, created: -60, started: -60, finished: -50);
|
|
var newDone = Job(JobState.Done, created: -40, started: -40, finished: -10);
|
|
var failed = Job(JobState.Failed, created: -30, started: -30, finished: -20);
|
|
var queuedLow = Job(JobState.Queued, created: -50, priority: JobPriority.Background);
|
|
var queuedOld = Job(JobState.Queued, created: -45);
|
|
var queuedNew = Job(JobState.Queued, created: -5);
|
|
var queuedUrgent = Job(JobState.Queued, created: -1, priority: JobPriority.User);
|
|
var paused = Job(JobState.Paused, created: -35, started: -35);
|
|
var runningLate = Job(JobState.Running, created: -8, started: -3);
|
|
var runningEarly = Job(JobState.Running, created: -9, started: -7);
|
|
foreach (var j in new[] { oldDone, newDone, failed, queuedLow, queuedOld, queuedNew, queuedUrgent, paused, runningLate, runningEarly }) model.Apply(j);
|
|
|
|
var order = model.Ordered().Select(e => e.Id).ToList();
|
|
Assert.SequenceEqual(
|
|
new[] { runningEarly, runningLate, paused, queuedUrgent, queuedOld, queuedNew, queuedLow, newDone, failed, oldDone }.Select(j => j.Id),
|
|
order);
|
|
|
|
Assert.Equal(1, model.QueuePosition(queuedUrgent.Id));
|
|
Assert.Equal(2, model.QueuePosition(queuedOld.Id));
|
|
Assert.Equal(4, model.QueuePosition(queuedLow.Id));
|
|
Assert.Equal(0, model.QueuePosition(runningEarly.Id));
|
|
Assert.Equal(2, model.RunningCount);
|
|
Assert.Equal(4, model.QueuedCount);
|
|
}
|
|
|
|
[Test]
|
|
public void FiltersCountAndHideClearedHistory()
|
|
{
|
|
var model = new JobListModel();
|
|
model.Apply(Job(JobState.Running, started: -1));
|
|
model.Apply(Job(JobState.Paused, started: -2));
|
|
model.Apply(Job(JobState.Queued));
|
|
model.Apply(Job(JobState.Done, started: -30, finished: -20));
|
|
model.Apply(Job(JobState.Done, started: -5, finished: -2));
|
|
model.Apply(Job(JobState.Failed, started: -6, finished: -4));
|
|
model.Apply(Job(JobState.Cancelled, started: -7, finished: -6));
|
|
|
|
Assert.Equal(7, model.CountOf(JobFilter.All));
|
|
Assert.Equal(2, model.CountOf(JobFilter.Running));
|
|
Assert.Equal(1, model.CountOf(JobFilter.Queued));
|
|
Assert.Equal(2, model.CountOf(JobFilter.Done));
|
|
Assert.Equal(2, model.CountOf(JobFilter.Failed));
|
|
|
|
var cleared = T0.AddMinutes(-10);
|
|
Assert.Equal(1, model.CountOf(JobFilter.Done, cleared));
|
|
Assert.Equal(6, model.Ordered(JobFilter.All, null, cleared).Count);
|
|
Assert.Equal(3, model.Ordered(JobFilter.All, null, T0).Count); // only the active jobs remain
|
|
}
|
|
|
|
[Test]
|
|
public void SearchMatchesTargetAndKind()
|
|
{
|
|
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
|
var model = new JobListModel();
|
|
model.Apply(Job(JobState.Queued, kind: JobKind.Render, label: "Harbour sunset → 4K"));
|
|
model.Apply(Job(JobState.Queued, kind: JobKind.Verify, label: "Archive · 2024"));
|
|
Assert.Equal(1, model.Ordered(JobFilter.All, "harbour").Count);
|
|
Assert.Equal(1, model.Ordered(JobFilter.All, "verify").Count);
|
|
Assert.Equal(2, model.Ordered(JobFilter.All, " ").Count);
|
|
Assert.Empty(model.Ordered(JobFilter.All, "comet"));
|
|
}
|
|
|
|
[Test]
|
|
public void ProgressMergesIntoRunningJobsOnly()
|
|
{
|
|
var model = new JobListModel();
|
|
var running = Job(JobState.Running, started: -1, done: 10, total: 100);
|
|
var queued = Job(JobState.Queued);
|
|
model.Apply(running);
|
|
model.Apply(queued);
|
|
|
|
Assert.True(model.Apply(Progress(running.Id, 62, 100, 11.3, TimeSpan.FromMinutes(2))));
|
|
Assert.False(model.Apply(Progress(queued.Id, 5, 100)));
|
|
Assert.False(model.Apply(Progress(Guid.CreateVersion7(), 5, 100)));
|
|
|
|
var entry = model[running.Id]!;
|
|
Assert.Equal(62, entry.Done);
|
|
Assert.Approximately(0.62, entry.Fraction!.Value, 1e-9);
|
|
Assert.Equal(11.3, entry.ItemsPerSecond);
|
|
Assert.Same(entry, model.Current);
|
|
Assert.Equal(0, model[queued.Id]!.Done);
|
|
|
|
// Finishing drops the live progress and falls back to the stored snapshot.
|
|
model.Apply(running with { State = JobState.Done, ProgressDone = 100, Finished = T0 });
|
|
Assert.Null(model[running.Id]!.Live);
|
|
Assert.Equal(100, model[running.Id]!.Done);
|
|
Assert.Null(model.Current);
|
|
}
|
|
|
|
[Test]
|
|
public void ALoadedPageNeverOverwritesANewerEvent()
|
|
{
|
|
var model = new JobListModel();
|
|
var queued = Job(JobState.Queued);
|
|
var readAt = model.Stamp; // page requested
|
|
model.Apply(queued with { State = JobState.Running, Started = T0 }); // event arrives first
|
|
Assert.False(model.ApplyLoaded(queued, readAt)); // the stale page row is ignored
|
|
Assert.Equal(JobState.Running, model[queued.Id]!.State);
|
|
|
|
var other = Job(JobState.Done, started: -3, finished: -1);
|
|
Assert.True(model.ApplyLoaded(other, model.Stamp));
|
|
Assert.True(model.Apply(other with { State = JobState.Queued, Finished = null }));
|
|
Assert.Equal(JobState.Queued, model[other.Id]!.State);
|
|
}
|
|
|
|
[Test]
|
|
public void CurrentPrefersTheJobWithLiveProgress()
|
|
{
|
|
var model = new JobListModel();
|
|
var a = Job(JobState.Running, started: -10);
|
|
var b = Job(JobState.Running, started: -1);
|
|
model.Apply(a);
|
|
model.Apply(b);
|
|
Assert.Equal(a.Id, model.Current!.Id);
|
|
model.Apply(Progress(b.Id, 1, 2));
|
|
Assert.Equal(b.Id, model.Current!.Id);
|
|
}
|
|
|
|
[Test]
|
|
public void ClaimOrderMatchesTheRepository()
|
|
{
|
|
var older = Job(JobState.Queued, created: -10);
|
|
var newer = Job(JobState.Queued, created: -5);
|
|
var urgent = Job(JobState.Queued, created: -1, priority: JobPriority.User);
|
|
Assert.True(JobListModel.ClaimsBefore(older, newer));
|
|
Assert.True(JobListModel.ClaimsBefore(urgent, older));
|
|
Assert.False(JobListModel.ClaimsBefore(newer, older));
|
|
}
|
|
|
|
[Test]
|
|
public void ThePriorityQueueOrdersTheQueueAsTheEngineClaimsIt()
|
|
{
|
|
var model = new JobListModel();
|
|
var verify = Job(JobState.Queued, created: -30, priority: JobPriority.User, kind: JobKind.Verify);
|
|
var scan = Job(JobState.Queued, created: -20, kind: JobKind.Scan);
|
|
var render = Job(JobState.Queued, created: -1, kind: JobKind.Render);
|
|
foreach (var j in new[] { verify, scan, render }) model.Apply(j);
|
|
Assert.SequenceEqual(new[] { verify.Id, scan.Id, render.Id }, model.Ordered().Select(e => e.Id));
|
|
|
|
// Owner review 1: on, renders come first and verifies last, whatever their age and priority.
|
|
model.PriorityQueue = new JobPriorityQueue { Enabled = true };
|
|
Assert.SequenceEqual(new[] { render.Id, scan.Id, verify.Id }, model.Ordered().Select(e => e.Id));
|
|
Assert.Equal((1, 2, 3), (model.QueuePosition(render.Id), model.QueuePosition(scan.Id), model.QueuePosition(verify.Id)));
|
|
}
|
|
|
|
[Test]
|
|
public void TextsDescribeTheJob()
|
|
{
|
|
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
|
var running = new JobEntry(Job(JobState.Running, kind: JobKind.Render, label: "Harbour sunset", started: -3))
|
|
{
|
|
Live = Progress(Guid.Empty, 2232, 3600, 11.3, TimeSpan.FromMinutes(2)),
|
|
};
|
|
Assert.Equal("Render · Harbour sunset · 2,232 / 3,600 · 11.3 fps · 2 min left", JobText.Bar(running));
|
|
Assert.Equal("2 min", JobText.Left(running, 0));
|
|
// Imports and verifies count bytes; scans count folders; frame jobs read in fps (owner review 1).
|
|
Assert.Equal("118\u00A0B/s", JobText.Speed(JobKind.Import, 118));
|
|
Assert.Equal(JobText.Speed(JobKind.Verify, 57_000_000), Loc.L("Jobs.Speed.Bytes", Formatting.Bytes(57_000_000)));
|
|
Assert.Equal("4/s", JobText.Speed(JobKind.Scan, 4));
|
|
Assert.Equal("1.7 fps", JobText.Speed(JobKind.Proxies, 1.7));
|
|
Assert.Equal(string.Empty, JobText.Speed(JobKind.Render, null));
|
|
Assert.Equal("this PC", JobText.Where("STUDIO#2", "studio"));
|
|
Assert.Equal("render-box", JobText.Where("render-box", "studio"));
|
|
|
|
var queued = new JobEntry(Job(JobState.Queued));
|
|
Assert.Equal("next", JobText.Left(queued, 1));
|
|
Assert.Equal("after 2", JobText.Left(queued, 3));
|
|
|
|
var done = new JobEntry(Job(JobState.Done, started: -10, finished: -7));
|
|
Assert.Equal("done · 3:00", JobText.State(done));
|
|
}
|
|
|
|
[Test]
|
|
public void TheWorkersReadoutCountsOnlyJobsOfThisPc()
|
|
{
|
|
var model = new JobListModel();
|
|
model.Apply(Job(JobState.Running, started: -1) with { NodeId = "STUDIO#0" });
|
|
model.Apply(Job(JobState.Running, started: -2) with { NodeId = "studio#3" });
|
|
model.Apply(Job(JobState.Running, started: -3) with { NodeId = "render-box#0" });
|
|
model.Apply(Job(JobState.Running, started: -4));
|
|
model.Apply(Job(JobState.Done, started: -9, finished: -8) with { NodeId = "studio#1" });
|
|
|
|
Assert.Equal(4, model.RunningCount);
|
|
Assert.Equal(2, model.RunningOn("studio"));
|
|
Assert.True(JobText.IsLocal("studio#2", "STUDIO"));
|
|
Assert.False(JobText.IsLocal("studio-2", "studio"));
|
|
Assert.False(JobText.IsLocal(null, "studio"));
|
|
}
|
|
|
|
[Test]
|
|
public void RowsAreNamedByKindAndTarget()
|
|
{
|
|
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
|
Assert.Equal("Render · Harbour sunset", JobText.Name(Job(JobState.Running, kind: JobKind.Render, label: "Harbour sunset")));
|
|
Assert.Equal("Proxies", JobText.Name(Job(JobState.Queued)));
|
|
}
|
|
|
|
private static Job Job(JobState state, int created = 0, int? started = null, int? finished = null, JobPriority priority = JobPriority.Normal,
|
|
JobKind kind = JobKind.Proxies, string? label = null, long done = 0, long total = 0) => new()
|
|
{
|
|
Id = Guid.CreateVersion7(),
|
|
Kind = kind,
|
|
State = state,
|
|
Priority = priority,
|
|
TargetLabel = label,
|
|
ProgressDone = done,
|
|
ProgressTotal = total,
|
|
Created = T0.AddMinutes(created),
|
|
Started = started is { } s ? T0.AddMinutes(s) : null,
|
|
Finished = finished is { } f ? T0.AddMinutes(f) : null,
|
|
};
|
|
|
|
private static JobProgressInfo Progress(Guid id, long done, long total, double? rate = null, TimeSpan? eta = null) =>
|
|
new(id, JobKind.Render, null, done, total, rate, eta, null);
|
|
}
|