fix(processing): concurrent renders keep their own names; analysis status under the lock; server announces changes
A render reserves the output name it picks, so the same preset queued twice no longer overwrites one output with the other; render rows take ids from their job and entry, so a resumed job recognises only its own outputs and never deletes another render's file. A light pass records its status under the sequence lock and cannot clear a deep pass's. Renders and Auto value changes made by the server engine publish sequenceChanged events. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
9 files changed
+316
-56
No files matched your search
@@ -45,11 +45,11 @@ internal sealed class ProcessingFixture : IAsyncDisposable
|
||||
|
||||
public static async Task<ProcessingFixture> CreateAsync(TestContext context) => new(await ArchiveFixture.CreateAsync(context), new GateDecoder());
|
||||
|
||||
/// <summary>A started engine with the processing handlers, and the archive's when asked (one worker, fast checkpoints).</summary>
|
||||
public async Task<JobEngine> StartEngineAsync(bool withArchive = false)
|
||||
/// <summary>A started engine with the processing handlers, and the archive's when asked (one worker unless asked, fast checkpoints).</summary>
|
||||
public async Task<JobEngine> StartEngineAsync(bool withArchive = false, int workers = 1)
|
||||
{
|
||||
_engine = new JobEngine(Db, [.. withArchive ? Archive.Service.CreateJobHandlers() : [], .. Processing.CreateJobHandlers()],
|
||||
new JobEngineOptions { Workers = 1, WorkerId = "test", PollInterval = TimeSpan.FromMilliseconds(50), CheckpointInterval = TimeSpan.FromMilliseconds(50) });
|
||||
new JobEngineOptions { Workers = workers, WorkerId = "test", PollInterval = TimeSpan.FromMilliseconds(50), CheckpointInterval = TimeSpan.FromMilliseconds(50) });
|
||||
await _engine.StartAsync(Ct);
|
||||
return _engine;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using Titano.Core.Imaging.Decoders;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Core.Model;
|
||||
using Titano.Core.Project;
|
||||
using Titano.Core.Video;
|
||||
using Titano.Data.Jobs;
|
||||
using Titano.Data.Processing;
|
||||
using Titano.Testing;
|
||||
@@ -126,18 +127,13 @@ public sealed class RenderJobTests(TestContext context)
|
||||
Directory.CreateDirectory(exports);
|
||||
var recorded = Encoding.ASCII.GetBytes("RIFF recorded before the crash");
|
||||
await File.WriteAllBytesAsync(output, recorded, fx.Ct);
|
||||
await fx.Db.Renders.InsertAsync(new Render
|
||||
{
|
||||
Id = Guid.CreateVersion7(),
|
||||
SequenceId = sequence.Id,
|
||||
PresetName = "MJPEG",
|
||||
OutputPath = "Synthetic/exports/clip-MJPEG.avi",
|
||||
Created = DateTimeOffset.UtcNow,
|
||||
}, fx.Ct);
|
||||
// The crash came after the job recorded its first entry and before its checkpoint said so.
|
||||
var jobId = Guid.CreateVersion7();
|
||||
await fx.Db.Renders.InsertAsync(RecordedRender(sequence, Titano.Data.Processing.Jobs.RenderJobHandler.RenderId(jobId, 0)), fx.Ct);
|
||||
await fx.StartEngineAsync();
|
||||
|
||||
var job = await fx.Archive.EnqueueWithCheckpointAsync(fx.Engine, ProcessingJobs.Render(sequence, Mjpeg with { Batch = ["gif-preview"] }, 96, 64),
|
||||
new RenderCheckpoint([], 0, output).ToJson());
|
||||
new RenderCheckpoint([], 0, output).ToJson(), jobId);
|
||||
await fx.WaitForAsync(job.Id, JobState.Done);
|
||||
|
||||
var kept = await File.ReadAllBytesAsync(output, fx.Ct);
|
||||
@@ -146,6 +142,74 @@ public sealed class RenderJobTests(TestContext context)
|
||||
Assert.Count(2, await fx.Db.Renders.ListBySequenceAsync(sequence.Id, fx.Ct));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ARenderResumedAfterAnotherRecordedItsNameKeepsThatOutput()
|
||||
{
|
||||
await using var fx = await ProcessingFixture.CreateAsync(context);
|
||||
var sequence = await fx.AddAsync(Scene());
|
||||
var exports = fx.Folder(sequence).Exports;
|
||||
var output = Path.Combine(exports, "clip-MJPEG.avi");
|
||||
Directory.CreateDirectory(exports);
|
||||
// While this job waited to resume, another render of the same preset finished under the name it had chosen.
|
||||
var other = Encoding.ASCII.GetBytes("RIFF another render's output");
|
||||
await File.WriteAllBytesAsync(output, other, fx.Ct);
|
||||
await fx.Db.Renders.InsertAsync(RecordedRender(sequence, Guid.CreateVersion7()), fx.Ct);
|
||||
await fx.StartEngineAsync();
|
||||
|
||||
var job = await fx.Archive.EnqueueWithCheckpointAsync(fx.Engine, ProcessingJobs.Render(sequence, Mjpeg, 96, 64), new RenderCheckpoint([], 0, output).ToJson());
|
||||
await fx.WaitForAsync(job.Id, JobState.Done);
|
||||
|
||||
var kept = await File.ReadAllBytesAsync(output, fx.Ct);
|
||||
Assert.BytesEqual(other, kept);
|
||||
Assert.SequenceEqual(["clip-MJPEG (2).avi", "clip-MJPEG.avi"], Entries(exports));
|
||||
Assert.Count(2, await fx.Db.Renders.ListBySequenceAsync(sequence.Id, fx.Ct));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ConcurrentRendersOfOnePresetKeepBothOutputs()
|
||||
{
|
||||
await using var fx = await ProcessingFixture.CreateAsync(context);
|
||||
var sequence = await fx.AddAsync(Scene());
|
||||
await fx.StartEngineAsync(workers: 2);
|
||||
|
||||
var first = await fx.EnqueueAsync(ProcessingJobs.Render(sequence, Mjpeg, 96, 64));
|
||||
var second = await fx.EnqueueAsync(ProcessingJobs.Render(sequence, Mjpeg, 96, 64));
|
||||
await fx.WaitForAsync(first.Id, JobState.Done);
|
||||
await fx.WaitForAsync(second.Id, JobState.Done);
|
||||
|
||||
Assert.SequenceEqual(["clip-MJPEG (2).avi", "clip-MJPEG.avi"], Entries(fx.Folder(sequence).Exports));
|
||||
var renders = await fx.Db.Renders.ListBySequenceAsync(sequence.Id, fx.Ct);
|
||||
Assert.Equal(2, renders.Select(r => r.OutputPath).Distinct().Count());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ANameBeingWrittenIsNotPickedAgain()
|
||||
{
|
||||
var folder = context.CreateTempDirectory("exports");
|
||||
var name = new ExportNameContext { Date = new DateTime(2026, 6, 1), Title = "Roof", PresetName = "MJPEG", Codec = VideoCodec.Mjpeg };
|
||||
using var a = new OutputNames();
|
||||
using var b = new OutputNames();
|
||||
var first = a.Reserve(taken => ExportNaming.OutputPath(folder, "{title}", name, taken));
|
||||
var second = b.Reserve(taken => ExportNaming.OutputPath(folder, "{title}", name, taken));
|
||||
Assert.Equal((Path.Combine(folder, "Roof.avi"), Path.Combine(folder, "Roof (2).avi")), (first, second));
|
||||
Assert.False(b.TryReserve(first), "held by the first render");
|
||||
|
||||
a.Dispose();
|
||||
using var c = new OutputNames();
|
||||
Assert.Equal(first, c.Reserve(taken => ExportNaming.OutputPath(folder, "{title}", name, taken)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RenderRowIdsAreStablePerJobAndEntry()
|
||||
{
|
||||
var job = Guid.CreateVersion7();
|
||||
var id = Titano.Data.Processing.Jobs.RenderJobHandler.RenderId(job, 0);
|
||||
Assert.Equal(id, Titano.Data.Processing.Jobs.RenderJobHandler.RenderId(job, 0));
|
||||
Assert.NotEqual(id, Titano.Data.Processing.Jobs.RenderJobHandler.RenderId(job, 1));
|
||||
Assert.NotEqual(id, Titano.Data.Processing.Jobs.RenderJobHandler.RenderId(Guid.CreateVersion7(), 0));
|
||||
Assert.Equal(8, id.Version);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AServerTakesOnlyTheRendersItsManagedEncodersProduce()
|
||||
{
|
||||
@@ -160,6 +224,10 @@ public sealed class RenderJobTests(TestContext context)
|
||||
Assert.False(Accepts(new ExportSettings { Preset = new Auto<string>().WithManual("4k-hevc") }), "HEVC needs a render node");
|
||||
Assert.False(Accepts(Mjpeg with { Batch = ["1080p-h264"] }), "one MP4 in the batch");
|
||||
Assert.True(handler.Accepts(new Job { Id = Guid.CreateVersion7(), Kind = JobKind.Render, ParametersJson = "{}" }), "unreadable: fails with its reason");
|
||||
Assert.True(handler.Accepts(new Job { Id = Guid.CreateVersion7(), Kind = JobKind.Render, ParametersJson = WithPreset("""{"preset":{},"Preset":{}}""") }),
|
||||
"a member given twice: fails with its reason");
|
||||
Assert.True(handler.Accepts(new Job { Id = Guid.CreateVersion7(), Kind = JobKind.Render, ParametersJson = WithPreset("""{"preset":{"isAuto":false,"manual":"mjpeg-avi"},"batch":null}""") }),
|
||||
"a null batch is no batch");
|
||||
|
||||
var client = new ProcessingService(fx.Db).CreateJobHandlers().Single(h => h.Kind == JobKind.Render);
|
||||
Assert.False(client is ISelectiveJobHandler, "a client renders whatever it is given");
|
||||
@@ -177,6 +245,19 @@ public sealed class RenderJobTests(TestContext context)
|
||||
Assert.Equal((3840, 2160), (parameters[2].Width, parameters[2].Height));
|
||||
}
|
||||
|
||||
/// <summary>MJPEG job parameters whose preset JSON is <paramref name="presetJson"/>.</summary>
|
||||
private static string WithPreset(string presetJson) => System.Text.Json.JsonSerializer.Serialize(
|
||||
new Titano.Protocol.RenderJobParameters("MJPEG", presetJson, "mjpeg", 96, 64, false, null), Titano.Protocol.ProtocolJson.Default.RenderJobParameters);
|
||||
|
||||
private static Render RecordedRender(Sequence sequence, Guid id) => new()
|
||||
{
|
||||
Id = id,
|
||||
SequenceId = sequence.Id,
|
||||
PresetName = "MJPEG",
|
||||
OutputPath = "Synthetic/exports/clip-MJPEG.avi",
|
||||
Created = DateTimeOffset.UtcNow,
|
||||
};
|
||||
|
||||
private static List<string> Entries(string folder) =>
|
||||
Directory.Exists(folder) ? [.. Directory.EnumerateFileSystemEntries(folder).Select(e => Path.GetFileName(e)).Order(StringComparer.Ordinal)] : [];
|
||||
|
||||
|
||||
Reference in new issue
Block a user