wip(processing): analysis and render job handlers, render node client (interrupted)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
30 files changed
+2262
-21
No files matched your search
@@ -0,0 +1,120 @@
|
||||
using System.Text;
|
||||
using Titano.Core.Codecs.Jpeg;
|
||||
using Titano.Core.Diagnostics.Synthetic;
|
||||
using Titano.Core.Export;
|
||||
using Titano.Core.Imaging.Decoders;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Core.Project;
|
||||
using Titano.Data.Archiving;
|
||||
using Titano.Data.Processing;
|
||||
using Titano.Protocol;
|
||||
using Titano.Protocol.Client;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.Server.Tests.Jobs;
|
||||
|
||||
/// <summary>The desktop client's render node (managed encoders here) against the in-process server.</summary>
|
||||
[Category("processing")]
|
||||
public sealed class RenderNodeClientTests(TestContext context)
|
||||
{
|
||||
private const int Frames = 12;
|
||||
|
||||
private static readonly ExportSettings Mjpeg = new()
|
||||
{
|
||||
Preset = new Auto<string>().WithManual("mjpeg-avi"),
|
||||
Overrides = new ExportOverrides { Width = 96, Height = 64 },
|
||||
NameTemplate = "{title} - {codec}",
|
||||
};
|
||||
|
||||
[Test]
|
||||
public async Task ANodeClaimsRendersWithManagedEncodersAndUploadsTheResult()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context);
|
||||
var (editor, _, token) = await server.UserAsync("alberto", "editor", renderNode: true);
|
||||
var sequenceId = await UploadSequenceAsync(editor, Photos());
|
||||
var job = await CreateRenderAsync(server, editor, sequenceId);
|
||||
|
||||
using var client = new TitanoClient(server.HttpBase, new CertificatePinning([]), "studio-pc") { Token = token };
|
||||
var cache = context.CreateTempDirectory("node");
|
||||
await using var node = Node(client, cache);
|
||||
Assert.True(await node.RunOnceAsync(context.Cancellation), "a job was claimed");
|
||||
Assert.False(await node.RunOnceAsync(context.Cancellation), "the queue is empty");
|
||||
|
||||
var done = await JobApiTests.GetAsync(editor, job.Id);
|
||||
Assert.Equal("done", done.State);
|
||||
var render = (await server.Database.Renders.ListBySequenceAsync(sequenceId)).Single();
|
||||
Assert.Equal(("studio-pc", "mjpeg", 96, 64), (render.ProducedBy, render.Codec, render.Width, render.Height));
|
||||
var sequence = (await server.Database.Sequences.GetAsync(sequenceId))!;
|
||||
var file = await File.ReadAllBytesAsync(Path.Combine(server.Options.ArchivePath, render.OutputPath));
|
||||
Assert.Equal(("RIFF", "AVI "), (Encoding.ASCII.GetString(file, 0, 4), Encoding.ASCII.GetString(file, 8, 4)));
|
||||
Assert.Equal($"{sequence.Folder}/exports/{sequence.DisplayTitle} - MJPEG.avi", render.OutputPath);
|
||||
Assert.Equal(1, sequence.RenderedCount);
|
||||
// Originals stay cached by content for the next job; the job's own folder is gone.
|
||||
Assert.Count(Frames, Directory.GetFiles(Path.Combine(cache, "originals"), "*.jpg", SearchOption.AllDirectories));
|
||||
Assert.False(Directory.EnumerateFileSystemEntries(Path.Combine(cache, "jobs")).Any(), "job folder removed");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ANodeReportsWhyItCouldNotRender()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context);
|
||||
var (editor, _, token) = await server.UserAsync("alberto", "editor", renderNode: true);
|
||||
// Uploads are opaque to the server's fake ingest: these "photos" decode to nothing.
|
||||
var sequenceId = await UploadSequenceAsync(editor, [Uploads.Photo(4000, 1), Uploads.Photo(4000, 2)]);
|
||||
var job = await CreateRenderAsync(server, editor, sequenceId);
|
||||
|
||||
using var client = new TitanoClient(server.HttpBase, new CertificatePinning([]), "studio-pc") { Token = token };
|
||||
await using var node = Node(client, context.CreateTempDirectory("node"));
|
||||
Assert.True(await node.RunOnceAsync(context.Cancellation), "a job was claimed");
|
||||
|
||||
var failed = await JobApiTests.GetAsync(editor, job.Id);
|
||||
var first = (await server.Database.Frames.ListBySequenceAsync(sequenceId))[0];
|
||||
Assert.Equal(("failed", Loc.L("Export.Render.FrameUnreadable", "1", first.FileName)), (failed.State, failed.Error));
|
||||
Assert.Empty(await server.Database.Renders.ListBySequenceAsync(sequenceId));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ANodeOffersOnlyEncodersWhoseOutputIsOneFile()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context);
|
||||
var (_, _, token) = await server.UserAsync("alberto", "editor", renderNode: true);
|
||||
using var client = new TitanoClient(server.HttpBase, new CertificatePinning([]), "studio-pc") { Token = token };
|
||||
await using var node = Node(client, context.CreateTempDirectory("node"));
|
||||
|
||||
var id = await node.RegisterAsync(context.Cancellation);
|
||||
var registered = (await client.ListNodesAsync(context.Cancellation)).Single(n => n.Id == id);
|
||||
Assert.SequenceEqual(["apng", "gif", "mjpeg"], registered.Encoders.Select(e => e.Codec).Order(StringComparer.Ordinal));
|
||||
}
|
||||
|
||||
private static RenderNodeClient Node(TitanoClient client, string cache) =>
|
||||
new(client, new ProcessingOptions { Archive = new ArchiveServiceOptions { Decoder = DecoderFactory.CreateServer() } },
|
||||
new RenderNodeOptions { ClientName = "studio-pc", CacheDirectory = cache, ProgressInterval = TimeSpan.Zero });
|
||||
|
||||
private static async Task<JobDto> CreateRenderAsync(TestServer server, HttpClient editor, Guid sequenceId)
|
||||
{
|
||||
var sequence = (await server.Database.Sequences.GetAsync(sequenceId))!;
|
||||
var request = ProcessingJobs.Render(sequence, Mjpeg, 96, 64);
|
||||
return await JobApiTests.CreateAsync(editor, "render", sequenceId, request.ParametersJson);
|
||||
}
|
||||
|
||||
/// <summary>Uploads the photos as IMG_0001.JPG… into one new sequence; returns its id.</summary>
|
||||
private static async Task<Guid> UploadSequenceAsync(HttpClient client, IReadOnlyList<byte[]> photos)
|
||||
{
|
||||
Guid? sequenceId = null;
|
||||
for (var i = 0; i < photos.Count; i++)
|
||||
sequenceId = (await Uploads.UploadAsync(client, photos[i], $"IMG_{i + 1:0000}.JPG", sequenceId)).SequenceId;
|
||||
return sequenceId!.Value;
|
||||
}
|
||||
|
||||
private static List<byte[]> Photos()
|
||||
{
|
||||
var scene = SyntheticSequence.Create(new SyntheticSequenceOptions { FrameCount = Frames, StartEv = 0.5, EndEv = -0.5 });
|
||||
var photos = new List<byte[]>(Frames);
|
||||
for (var i = 0; i < Frames; i++)
|
||||
{
|
||||
using var image = scene.Render(i);
|
||||
photos.Add(JpegEncoder.Encode(image, new JpegEncodeOptions { Quality = 90 }));
|
||||
}
|
||||
return photos;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user