WIP of the interrupted fix stage. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
82 lines
3.4 KiB
C#
82 lines
3.4 KiB
C#
using Titano.App.Editor;
|
|
using Titano.Core.Model;
|
|
using Titano.Testing;
|
|
|
|
namespace Titano.App.Tests.Editor;
|
|
|
|
/// <summary>The jobs of the open sequence: the busy lock, Analyse queued twice, and the server job the header shows.</summary>
|
|
public sealed class SequenceJobsTests
|
|
{
|
|
private static readonly Guid Sunset = Guid.CreateVersion7();
|
|
|
|
[Test]
|
|
public void OnlyAnalysesAndRendersOfTheSequenceCount()
|
|
{
|
|
var jobs = new SequenceJobs(Sunset);
|
|
Assert.False(jobs.Track(Job(JobKind.Render, JobState.Running, Guid.CreateVersion7())), "another sequence");
|
|
Assert.False(jobs.Track(Job(JobKind.Proxies, JobState.Running)), "not an analysis or a render");
|
|
Assert.Null(jobs.Shown);
|
|
Assert.False(jobs.IsBusy);
|
|
}
|
|
|
|
[Test]
|
|
public void StatesChangeTheLockProgressAloneDoesNot()
|
|
{
|
|
var jobs = new SequenceJobs(Sunset);
|
|
var render = Job(JobKind.Render, JobState.Queued);
|
|
Assert.True(jobs.Track(render), "joined");
|
|
Assert.True(jobs.IsActive(render.Id));
|
|
Assert.False(jobs.IsBusy, "waiting does not lock the settings");
|
|
|
|
Assert.True(jobs.Track(render with { State = JobState.Running }), "started");
|
|
Assert.True(jobs.IsBusy);
|
|
Assert.False(jobs.Track(render with { State = JobState.Running, ProgressDone = 40, ProgressTotal = 96 }), "progress only");
|
|
Assert.Equal(40, jobs.Shown!.ProgressDone);
|
|
|
|
Assert.True(jobs.Track(render with { State = JobState.Paused }));
|
|
Assert.False(jobs.IsBusy, "a paused render holds nothing");
|
|
Assert.True(jobs.Track(render with { State = JobState.Failed }), "left");
|
|
Assert.False(jobs.IsActive(render.Id));
|
|
Assert.False(jobs.Track(render with { State = JobState.Failed }), "an ended job that is not tracked changes nothing");
|
|
}
|
|
|
|
[Test]
|
|
public void AnAnalysisWaitingOrPausedStillCountsAsQueued()
|
|
{
|
|
var jobs = new SequenceJobs(Sunset);
|
|
var analysis = Job(JobKind.DeepAnalyse, JobState.Paused);
|
|
jobs.Track(analysis);
|
|
Assert.True(jobs.IsAnalysing, "Analyse would queue a second one");
|
|
jobs.Track(analysis with { State = JobState.Done });
|
|
Assert.False(jobs.IsAnalysing);
|
|
}
|
|
|
|
[Test]
|
|
public void TheHeaderShowsTheRunningJobThenThePausedThenTheOldestWaiting()
|
|
{
|
|
var jobs = new SequenceJobs(Sunset);
|
|
var now = DateTimeOffset.UtcNow;
|
|
var later = Job(JobKind.Render, JobState.Queued) with { Created = now };
|
|
var first = Job(JobKind.Render, JobState.Queued) with { Created = now.AddMinutes(-5) };
|
|
var paused = Job(JobKind.DeepAnalyse, JobState.Paused) with { Created = now.AddMinutes(-9), Started = now.AddMinutes(-8) };
|
|
var running = Job(JobKind.Render, JobState.Running) with { Created = now.AddMinutes(-1), Started = now };
|
|
foreach (var job in new[] { later, first }) jobs.Track(job);
|
|
Assert.Equal(first.Id, jobs.Shown!.Id);
|
|
jobs.Track(paused);
|
|
Assert.Equal(paused.Id, jobs.Shown!.Id);
|
|
jobs.Track(running);
|
|
Assert.Equal(running.Id, jobs.Shown!.Id);
|
|
jobs.Track(running with { State = JobState.Done });
|
|
Assert.Equal(paused.Id, jobs.Shown!.Id);
|
|
}
|
|
|
|
private static Job Job(JobKind kind, JobState state, Guid? target = null) => new()
|
|
{
|
|
Id = Guid.CreateVersion7(),
|
|
Kind = kind,
|
|
TargetIds = [target ?? Sunset],
|
|
State = state,
|
|
Created = DateTimeOffset.UtcNow,
|
|
};
|
|
}
|