Owner review 1, phase 1 (docs/requests/2026-10-15-owner-review-1.md). Thumbnail and proxy jobs over several sequences counted sequences while they checkpointed inside one: the rate decayed until the time left overflowed TimeSpan, the job failed while publishing progress and again while saving it, and stayed Running. The throughput is now seeded by the first window with progress, the time left is bounded (JobEta), saving progress never throws, image passes count frames, and job speeds use the right unit (bytes for verify and import). The debugger stops in WicDecoderProvider.cs when presets changed were cancelled preview decodes leaving synchronous thread-pool delegates; the editor's sources, LatestRunner and the render node's proxy task now keep them in their own tasks, and a cancellation is never an unreadable frame. GoPro DNGs converted by Adobe software were classified GPR and read only through their 8-bit preview, and Windows' preview-only DNG decoder was reported as a native decode. A DNG is GPR only when its raw image is VC-5, WIC decodes RAW only through the Raw Image Extension and never DNG, analyses and previews take an adequate embedded preview by choice while renders develop natively, and frames already indexed as GPR are reclassified by the next light analysis. Also records the owner's request (docs/requests), the BRIEF amendments (§8.1, §8.2, new §24), DECISIONS, CHANGELOG, STATUS and ARCHITECTURE. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
218 lines
9.8 KiB
C#
218 lines
9.8 KiB
C#
using System.Globalization;
|
|
using Titano.App.Infrastructure;
|
|
using Titano.App.Jobs;
|
|
using Titano.Core.Localization;
|
|
using Titano.Core.Model;
|
|
using Titano.Data.Jobs;
|
|
using Titano.Testing;
|
|
|
|
namespace Titano.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 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 B/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);
|
|
}
|