refactor!: rename Titano to Chronos and move CI and releases to Gitea (#6)
CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
The owner renamed the product and moved the repository to the self-hosted Gitea (https://gitea.encke-hake.ts.net/BalboSoft/Chronos) for more control, and asked for Actions and a first automatic release with the server package and the Windows exe (docs/requests/2026-10-23-chronos-gitea.md). - Chronos everywhere: a byte-exact rename of contents and paths, then a per-language review of the forms the old name's ending had dictated. - Gitea instead of GitHub: the update check, licence, issue and support links read ChronosReleasesUrl; the update check takes the highest stable version, offers a pre-release build its final release and reports a repository it cannot see as a failed check. EULA, security policy and Gitea issue forms live at the repository root. - Gitea Actions for the Linux act_runner (.gitea/workflows): CI, release, nightly image and performance gates in the .NET SDK container with git checkout and the system SQLite. The release cross-compiles the Windows programs, checks their icon, version and DPI manifest, packs installers and zips, publishes the Gitea release and pushes the server image (REGISTRY_TOKEN). Windows-only tests run in an opt-in job on a Windows runner (WINDOWS_RUNNER). - New Chronos.Tools commands: zip, gitea-release, postgres-ci (replaces the docker-exec script, which Gitea's service containers do not allow; the throw-away server runs without durability) and pe-check. - Timed tests take their budget from TestTiming (CHRONOS_TEST_TIME_FACTOR, 3 on the shared runner; the weekly performance gates keep theirs). BREAKING CHANGE: programs, settings, data folders, file types, environment variables and the Docker image use the new name; nothing is migrated from Titano, which never had a release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #6.
This commit is contained in:
1 parent
c99842cc86
commit
f2b58522b9
1801 files changed
+11804
-10676
No files matched your search
@@ -0,0 +1,139 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Data.Jobs;
|
||||
using Chronos.Protocol;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.Server.Tests.Jobs;
|
||||
|
||||
[Category("server")]
|
||||
public sealed class JobApiTests(TestContext context)
|
||||
{
|
||||
[Test]
|
||||
public async Task JobsMoveThroughPauseResumeAndDone()
|
||||
{
|
||||
var handler = new BlockingJobHandler(JobKind.DeepAnalyse);
|
||||
await using var server = await TestServer.StartAsync(context, services: s => s.AddSingleton<IJobHandler>(handler));
|
||||
var (editor, _, _) = await server.UserAsync("alberto", "editor");
|
||||
var sequence = await CreateSequenceAsync(editor);
|
||||
|
||||
var job = await CreateAsync(editor, "deep-analyse", sequence);
|
||||
Assert.Equal(("queued", "user", "Harbour sunset"), (job.State, job.Priority, job.TargetLabel));
|
||||
await handler.Started.Task.WaitAsync(TimeSpan.FromSeconds(10));
|
||||
await WaitForAsync(editor, job.Id, "running");
|
||||
|
||||
Assert.Equal("paused", (await ActAsync(editor, job.Id, "pause", HttpStatusCode.OK)).State);
|
||||
await WaitForAsync(editor, job.Id, "paused");
|
||||
await ActAsync(editor, job.Id, "pause", HttpStatusCode.Conflict);
|
||||
await ActAsync(editor, job.Id, "retry", HttpStatusCode.Conflict);
|
||||
|
||||
await ActAsync(editor, job.Id, "resume", HttpStatusCode.OK);
|
||||
await WaitForAsync(editor, job.Id, "running");
|
||||
handler.Release();
|
||||
var done = await WaitForAsync(editor, job.Id, "done");
|
||||
Assert.Equal((4L, 4L), (done.ProgressDone, done.ProgressTotal));
|
||||
await ActAsync(editor, job.Id, "cancel", HttpStatusCode.Conflict);
|
||||
|
||||
using var list = await editor.GetAsync("/api/v1/jobs?state=done&kind=deep-analyse");
|
||||
Assert.Equal(job.Id, (await list.ReadAsync(ProtocolJson.Default.PageJobDto)).Items.Single().Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FailedJobsRetryAndRunningJobsCancel()
|
||||
{
|
||||
var handler = new BlockingJobHandler(JobKind.Proxies) { FailWith = "decoder exploded" };
|
||||
await using var server = await TestServer.StartAsync(context, services: s => s.AddSingleton<IJobHandler>(handler));
|
||||
var (editor, _, _) = await server.UserAsync("alberto", "editor");
|
||||
var sequence = await CreateSequenceAsync(editor);
|
||||
|
||||
var job = await CreateAsync(editor, "proxies", sequence);
|
||||
var failed = await WaitForAsync(editor, job.Id, "failed");
|
||||
Assert.Equal("decoder exploded", failed.Error);
|
||||
Assert.Contains("decoder exploded", failed.LogTail);
|
||||
|
||||
await ActAsync(editor, job.Id, "retry", HttpStatusCode.OK);
|
||||
await WaitForAsync(editor, job.Id, "running");
|
||||
Assert.Equal("cancelled", (await ActAsync(editor, job.Id, "cancel", HttpStatusCode.OK)).State);
|
||||
await Task.Delay(200);
|
||||
Assert.Equal("cancelled", (await GetAsync(editor, job.Id)).State);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task WaitingJobsChangePriorityAndRightsAreChecked()
|
||||
{
|
||||
var handler = new BlockingJobHandler(JobKind.Thumbs);
|
||||
await using var server = await TestServer.StartAsync(context, o => o.Parallelism = 1, s => s.AddSingleton<IJobHandler>(handler));
|
||||
var (editor, _, _) = await server.UserAsync("alberto", "editor");
|
||||
var (viewer, _, _) = await server.UserAsync("marco", "viewer");
|
||||
var sequence = await CreateSequenceAsync(editor);
|
||||
|
||||
var first = await CreateAsync(editor, "thumbs", sequence);
|
||||
await WaitForAsync(editor, first.Id, "running");
|
||||
var second = await CreateAsync(editor, "thumbs", sequence);
|
||||
using (var lower = await editor.PostAsJsonAsync($"/api/v1/jobs/{second.Id}/priority", new JobPriorityRequest("background"), ProtocolJson.Default.JobPriorityRequest))
|
||||
Assert.Equal("background", (await lower.ReadAsync(ProtocolJson.Default.JobDto)).Priority);
|
||||
using (var bad = await editor.PostAsJsonAsync($"/api/v1/jobs/{second.Id}/priority", new JobPriorityRequest("urgent"), ProtocolJson.Default.JobPriorityRequest))
|
||||
await bad.ExpectErrorAsync(HttpStatusCode.BadRequest, "invalid_priority");
|
||||
|
||||
using (var foreign = await viewer.PostAsync($"/api/v1/jobs/{second.Id}/cancel", null)) await foreign.ExpectErrorAsync(HttpStatusCode.Forbidden, "forbidden");
|
||||
using (var create = await viewer.PostAsJsonAsync("/api/v1/jobs", new CreateJobRequest("thumbs", [sequence], null), ProtocolJson.Default.CreateJobRequest))
|
||||
await create.ExpectErrorAsync(HttpStatusCode.Forbidden, "forbidden");
|
||||
using (var unknown = await editor.PostAsJsonAsync("/api/v1/jobs", new CreateJobRequest("teleport", [sequence], null), ProtocolJson.Default.CreateJobRequest))
|
||||
await unknown.ExpectErrorAsync(HttpStatusCode.BadRequest, "invalid_job_kind");
|
||||
using (var unavailable = await editor.PostAsJsonAsync("/api/v1/jobs", new CreateJobRequest("deep-analyse", [sequence], null), ProtocolJson.Default.CreateJobRequest))
|
||||
await unavailable.ExpectErrorAsync(HttpStatusCode.Conflict, "job_unavailable");
|
||||
using (var render = await editor.PostAsJsonAsync("/api/v1/jobs", new CreateJobRequest("render", [sequence], "{}"), ProtocolJson.Default.CreateJobRequest))
|
||||
await render.ExpectErrorAsync(HttpStatusCode.BadRequest, "invalid_parameters");
|
||||
|
||||
var admin = await server.AdminAsync();
|
||||
using (var removed = await admin.PostAsync($"/api/v1/jobs/{second.Id}/cancel", null)) await removed.ExpectAsync(HttpStatusCode.OK);
|
||||
handler.Release();
|
||||
await WaitForAsync(editor, first.Id, "done");
|
||||
}
|
||||
|
||||
public static async Task<Guid> CreateSequenceAsync(HttpClient client, string title = "Harbour sunset")
|
||||
{
|
||||
using var created = await client.PostAsJsonAsync("/api/v1/sequences", new CreateSequenceRequest(title, null), ProtocolJson.Default.CreateSequenceRequest);
|
||||
await created.ExpectAsync(HttpStatusCode.Created);
|
||||
return (await created.ReadAsync(ProtocolJson.Default.SequenceDto)).Id;
|
||||
}
|
||||
|
||||
public static async Task<JobDto> CreateAsync(HttpClient client, string kind, Guid target, string? parameters = null)
|
||||
{
|
||||
using var response = await client.PostAsJsonAsync("/api/v1/jobs", new CreateJobRequest(kind, [target], parameters), ProtocolJson.Default.CreateJobRequest);
|
||||
await response.ExpectAsync(HttpStatusCode.Accepted);
|
||||
return await response.ReadAsync(ProtocolJson.Default.JobDto);
|
||||
}
|
||||
|
||||
public static async Task<JobDto> GetAsync(HttpClient client, Guid id)
|
||||
{
|
||||
using var response = await client.GetAsync($"/api/v1/jobs/{id}");
|
||||
return await response.ReadAsync(ProtocolJson.Default.JobDto);
|
||||
}
|
||||
|
||||
public static async Task<JobDto> WaitForAsync(HttpClient client, Guid id, string state)
|
||||
{
|
||||
var deadline = DateTime.UtcNow.AddSeconds(15);
|
||||
while (true)
|
||||
{
|
||||
var job = await GetAsync(client, id);
|
||||
if (job.State == state) return job;
|
||||
if (DateTime.UtcNow > deadline) Assert.Fail($"Job {id} is {job.State}, expected {state}");
|
||||
await Task.Delay(50);
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task<JobDto> ActAsync(HttpClient client, Guid id, string action, HttpStatusCode expected)
|
||||
{
|
||||
using var response = await client.PostAsync($"/api/v1/jobs/{id}/{action}", null);
|
||||
if (expected != HttpStatusCode.OK)
|
||||
{
|
||||
await response.ExpectErrorAsync(expected, "invalid_state");
|
||||
return await GetAsync(client, id);
|
||||
}
|
||||
await response.ExpectAsync(expected);
|
||||
return await response.ReadAsync(ProtocolJson.Default.JobDto);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,454 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Text;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Chronos.Core.Archiving;
|
||||
using Chronos.Core.Codecs.Jpeg;
|
||||
using Chronos.Core.Diagnostics.Synthetic;
|
||||
using Chronos.Core.Export;
|
||||
using Chronos.Core.Imaging;
|
||||
using Chronos.Core.Imaging.Decoders;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Core.Metadata;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Data.Archiving;
|
||||
using Chronos.Data.Processing;
|
||||
using Chronos.Protocol;
|
||||
using Chronos.Protocol.Client;
|
||||
using Chronos.Server.Jobs;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.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 ChronosClient(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 ANodeSkipsMissingFramesFetchesUnhashedOnesAndSendsTheProxiesAskedFor()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context);
|
||||
var (editor, _, token) = await server.UserAsync("alberto", "editor", renderNode: true);
|
||||
var sequenceId = await UploadSequenceAsync(editor, Photos()[..3]);
|
||||
await Uploads.UploadAsync(editor, [0, 0, 0, 24, .. "ftypheic"u8, 0, 0, 0, 0, .. "mif1heic"u8, .. Uploads.Photo(2000, 9)], "IMG_0004.HEIC", sequenceId);
|
||||
var frames = await server.Database.Frames.ListBySequenceAsync(sequenceId);
|
||||
// Frame 1 is gone from the server, frame 2 was adopted and never hashed, frame 3 is damaged (the server could not
|
||||
// decode it) and frame 4 is a HEIF the server cannot decode.
|
||||
File.Delete(Path.Combine(server.Options.ArchivePath, frames[0].RelativePath));
|
||||
await server.Database.Frames.UpdateFlagsAsync([frames[0].Id], FrameFlags.Missing, FrameFlags.None);
|
||||
await server.Database.Frames.UpdateFlagsAsync([frames[2].Id, frames[3].Id], FrameFlags.Undecodable, FrameFlags.None);
|
||||
await using (var session = await server.Database.Database.OpenAsync(context.Cancellation))
|
||||
{
|
||||
await session.ExecuteAsync("UPDATE frames SET sha256 = NULL WHERE id = $1", [frames[1].Id], context.Cancellation);
|
||||
await session.ExecuteAsync("UPDATE frames SET format = $1 WHERE id = $2", [(int)ImageFileFormat.Heif, frames[3].Id], context.Cancellation);
|
||||
}
|
||||
var job = await CreateRenderAsync(server, editor, sequenceId);
|
||||
|
||||
var requests = new RecordPaths(new SocketsHttpHandler());
|
||||
using var client = new ChronosClient(server.HttpBase, new CertificatePinning([]), "studio-pc", requests) { Token = token };
|
||||
// This PC decodes HEIF (WIC with the HEIF extension on Windows).
|
||||
await using var node = Node(client, context.CreateTempDirectory("node"), decoder: new ImageDecoder([new SolidHeif(), new ManagedDecoderProvider()]));
|
||||
Assert.True(await node.RunOnceAsync(context.Cancellation), "a job was claimed");
|
||||
|
||||
var done = await JobApiTests.GetAsync(editor, job.Id);
|
||||
Assert.Equal("done", done.State, done.Error);
|
||||
Assert.DoesNotContain($"/api/v1/frames/{frames[0].Id}/original", requests.Paths);
|
||||
Assert.Contains($"/api/v1/frames/{frames[1].Id}/original", requests.Paths);
|
||||
// The damaged frame stays out, as in the server's own render; the HEIF renders from its original here.
|
||||
Assert.DoesNotContain($"/api/v1/frames/{frames[2].Id}/original", requests.Paths);
|
||||
Assert.Contains($"/api/v1/frames/{frames[3].Id}/original", requests.Paths);
|
||||
var sequence = (await server.Database.Sequences.GetAsync(sequenceId))!;
|
||||
var proxy = new ArchivePaths(server.Options.ArchivePath).Sequence(sequence.Folder).Proxy(frames[3].Index);
|
||||
Assert.Equal(frames[3].CapturedAt, MetadataReader.Read(proxy).CapturedAt, "the proxy the server asked for, with the frame's capture time");
|
||||
Assert.Equal((96, 64), MetadataReader.Read(proxy).OrientedSize);
|
||||
}
|
||||
|
||||
[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 ChronosClient(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 ChronosClient(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));
|
||||
// Each encoder announces its own largest output, so the server matches job sizes per codec.
|
||||
Assert.True(registered.Encoders.All(e => (e.MaxWidth, e.MaxHeight) == (65535, 65535)), "per-encoder limits");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AStartedNodeRegistersBeatsClaimsAndStopsCleanly()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context);
|
||||
var (editor, _, token) = await server.UserAsync("alberto", "editor", renderNode: true);
|
||||
var sequenceId = await UploadSequenceAsync(editor, Photos());
|
||||
// A posted batch becomes one job per preset, so each output travels back on its own.
|
||||
var job = await CreateRenderAsync(server, editor, sequenceId, Mjpeg with { Batch = ["gif-preview"] });
|
||||
var gif = (await server.Database.Jobs.ListAsync(JobState.Queued, JobKind.Render)).Items.Single(j => j.Id != job.Id);
|
||||
|
||||
var claims = new CountClaims(new SocketsHttpHandler());
|
||||
using var client = new ChronosClient(server.HttpBase, new CertificatePinning([]), "studio-pc", claims) { Token = token };
|
||||
var cache = context.CreateTempDirectory("node");
|
||||
// Claims only when started and after each job: between them only heartbeats reach the server.
|
||||
var node = Node(client, cache, poll: TimeSpan.FromMinutes(5), heartbeat: TimeSpan.FromMilliseconds(100));
|
||||
node.Start();
|
||||
await JobApiTests.WaitForAsync(editor, job.Id, "done");
|
||||
await JobApiTests.WaitForAsync(editor, gif.Id, "done");
|
||||
// Past the claim that found the queue empty (the server touched the node before answering it), only heartbeats
|
||||
// move the node's last sign of life.
|
||||
await UntilAsync(() => Task.FromResult(claims.Answered >= 3), "the claim that found the queue empty");
|
||||
var beat = (await server.Database.RenderNodes.ListAsync()).Single().LastHeartbeat;
|
||||
await UntilAsync(async () => (await server.Database.RenderNodes.ListAsync()).Single().LastHeartbeat > beat, "a heartbeat");
|
||||
Assert.Equal(3, claims.Answered, "no claim since the queue was empty");
|
||||
await node.DisposeAsync();
|
||||
|
||||
Assert.True(node.Completion.IsCompleted, "stopped");
|
||||
Assert.SequenceEqual(["gif", "mjpeg"], (await server.Database.Renders.ListBySequenceAsync(sequenceId)).Select(r => r.Codec!).Order(StringComparer.Ordinal));
|
||||
Assert.False(Directory.EnumerateFileSystemEntries(Path.Combine(cache, "jobs")).Any(), "job folder removed");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ANodeRestartedDuringAJobDoesNotLeaveItRunning()
|
||||
{
|
||||
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);
|
||||
var cache = context.CreateTempDirectory("node");
|
||||
|
||||
// The first run stops while downloading (sign-out, exit): the job is still running on the server.
|
||||
var held = new HoldDownloads(new SocketsHttpHandler());
|
||||
using (var slow = new ChronosClient(server.HttpBase, new CertificatePinning([]), "studio-pc", held) { Token = token })
|
||||
{
|
||||
await using var first = Node(slow, cache);
|
||||
using var stopping = new CancellationTokenSource();
|
||||
var run = first.RunOnceAsync(stopping.Token);
|
||||
await held.Holding.Task.WaitAsync(TimeSpan.FromSeconds(30));
|
||||
Assert.Equal("running", (await JobApiTests.GetAsync(editor, job.Id)).State);
|
||||
await stopping.CancelAsync();
|
||||
Assert.True(await run, "the job was claimed");
|
||||
}
|
||||
Assert.Equal("running", (await JobApiTests.GetAsync(editor, job.Id)).State);
|
||||
|
||||
// Started again within the heartbeat timeout under the same name: registering gives the job back to the queue.
|
||||
using var client = new ChronosClient(server.HttpBase, new CertificatePinning([]), "studio-pc") { Token = token };
|
||||
await using var second = Node(client, cache);
|
||||
Assert.True(await second.RunOnceAsync(context.Cancellation), "the abandoned job was claimed again");
|
||||
|
||||
var done = await JobApiTests.GetAsync(editor, job.Id);
|
||||
Assert.Equal("done", done.State);
|
||||
Assert.Contains("Render node studio-pc restarted.", done.LogTail);
|
||||
Assert.Count(1, await server.Database.Renders.ListBySequenceAsync(sequenceId));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ADroppedDownloadIsResumedNotFailed()
|
||||
{
|
||||
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);
|
||||
|
||||
var cut = new CutFirst("original", new SocketsHttpHandler());
|
||||
using var client = new ChronosClient(server.HttpBase, new CertificatePinning([]), "studio-pc", cut) { Token = token };
|
||||
await using var node = Node(client, context.CreateTempDirectory("node"));
|
||||
Assert.True(await node.RunOnceAsync(context.Cancellation), "a job was claimed");
|
||||
|
||||
Assert.Equal("done", (await JobApiTests.GetAsync(editor, job.Id)).State);
|
||||
Assert.Equal(1, cut.Cuts);
|
||||
Assert.Equal(1, cut.Resumed);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ADroppedProxyIsFetchedWholeAgain()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context);
|
||||
var (editor, _, token) = await server.UserAsync("alberto", "editor", renderNode: true);
|
||||
var photos = Photos();
|
||||
var sequence = (await server.Database.Sequences.GetAsync(await UploadSequenceAsync(editor, photos)))!;
|
||||
// The archive has proxies of every frame (the test locator serves <folder>/proxies/NNNN.jpg).
|
||||
var proxies = Path.Combine(server.Options.ArchivePath, sequence.Folder, "proxies");
|
||||
Directory.CreateDirectory(proxies);
|
||||
foreach (var frame in await server.Database.Frames.ListBySequenceAsync(sequence.Id))
|
||||
await File.WriteAllBytesAsync(Path.Combine(proxies, $"{frame.Index:D4}.jpg"), photos[frame.Index]);
|
||||
await server.Database.Sequences.UpsertAsync(sequence with { Status = sequence.Status | SequenceStatus.ProxiesBuilt });
|
||||
var job = await JobApiTests.CreateAsync(editor, "render", sequence.Id, ProcessingJobs.Render(sequence, Mjpeg, 96, 64, useProxies: true).ParametersJson);
|
||||
|
||||
var cut = new CutFirst("proxy", new SocketsHttpHandler());
|
||||
using var client = new ChronosClient(server.HttpBase, new CertificatePinning([]), "studio-pc", cut) { 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.Equal("done", (await JobApiTests.GetAsync(editor, job.Id)).State);
|
||||
// Nothing verifies a proxy against a hash, so a retry never appends to what the dropped attempt left.
|
||||
Assert.Equal((1, 0), (cut.Cuts, cut.Resumed));
|
||||
Assert.False(Directory.Exists(Path.Combine(cache, "originals")), "no original needed");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ANodeLeavesARenderTheServerStartedToTheServer()
|
||||
{
|
||||
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);
|
||||
// The server's own engine was rendering it when it crashed: its checkpoint names its leftovers.
|
||||
Assert.NotNull(await server.Database.Jobs.TryClaimAsync(job.Id, "server:test#0"));
|
||||
Assert.True(await server.Database.Jobs.UpdateProgressAsync(job.Id, 3, 12, null, null, """{"done":[],"pending":0}""", null));
|
||||
await server.Database.Jobs.RequeueRunningAsync("server:test");
|
||||
|
||||
using var client = new ChronosClient(server.HttpBase, new CertificatePinning([]), "studio-pc") { Token = token };
|
||||
await using var node = Node(client, context.CreateTempDirectory("node"));
|
||||
Assert.False(await node.RunOnceAsync(context.Cancellation), "nothing for the node");
|
||||
Assert.Equal("queued", (await JobApiTests.GetAsync(editor, job.Id)).State);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ANodeRefusesABatchItCannotSendBack()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context);
|
||||
var (editor, user, token) = await server.UserAsync("alberto", "editor", renderNode: true);
|
||||
var sequence = (await server.Database.Sequences.GetAsync(await UploadSequenceAsync(editor, Photos())))!;
|
||||
// Queued as one job (an older server did not split batches).
|
||||
var request = ProcessingJobs.Render(sequence, Mjpeg with { Batch = ["gif-preview"] }, 96, 64);
|
||||
var job = await server.Services.GetRequiredService<JobEngineHost>().Engine
|
||||
.EnqueueAsync(request.Kind, request.Targets, request.Label, request.ParametersJson, request.Priority, user.Id);
|
||||
|
||||
using var client = new ChronosClient(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);
|
||||
Assert.Equal(("failed", Loc.L("Errors.Render.NodeBatch")), (failed.State, failed.Error));
|
||||
Assert.Empty(await server.Database.Renders.ListBySequenceAsync(sequence.Id));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ADownloadThatEndedBeforeItsCheckIsVerifiedNotFetchedAgain()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context);
|
||||
var (editor, _, token) = await server.UserAsync("alberto", "editor", renderNode: true);
|
||||
var photos = Photos();
|
||||
var sequenceId = await UploadSequenceAsync(editor, photos);
|
||||
await CreateRenderAsync(server, editor, sequenceId, Mjpeg);
|
||||
// A crash after the last byte arrived but before the hash check left a complete part file.
|
||||
var cache = context.CreateTempDirectory("node");
|
||||
var sha = Uploads.Sha(photos[0]);
|
||||
var part = Path.Combine(cache, "originals", sha[..2], sha + ".jpg.part");
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(part)!);
|
||||
await File.WriteAllBytesAsync(part, photos[0]);
|
||||
|
||||
using var client = new ChronosClient(server.HttpBase, new CertificatePinning([]), "studio-pc") { Token = token };
|
||||
await using var node = Node(client, cache);
|
||||
Assert.True(await node.RunOnceAsync(context.Cancellation), "a job was claimed");
|
||||
|
||||
Assert.Count(1, await server.Database.Renders.ListBySequenceAsync(sequenceId));
|
||||
Assert.FileMissing(part);
|
||||
Assert.FileExists(part[..^".part".Length]);
|
||||
}
|
||||
|
||||
private static RenderNodeClient Node(ChronosClient client, string cache, TimeSpan? poll = null, TimeSpan? heartbeat = null, ImageDecoder? decoder = null) =>
|
||||
new(client, new ProcessingOptions { Archive = new ArchiveServiceOptions { Decoder = decoder ?? DecoderFactory.CreateServer() } },
|
||||
new RenderNodeOptions
|
||||
{
|
||||
ClientName = "studio-pc",
|
||||
CacheDirectory = cache,
|
||||
ProgressInterval = TimeSpan.Zero,
|
||||
PollInterval = poll ?? TimeSpan.FromSeconds(10),
|
||||
HeartbeatInterval = heartbeat ?? TimeSpan.FromSeconds(30),
|
||||
RetryDelay = TimeSpan.FromMilliseconds(10),
|
||||
});
|
||||
|
||||
/// <summary>Holds every frame download until the request is cancelled.</summary>
|
||||
private sealed class HoldDownloads(HttpMessageHandler inner) : DelegatingHandler(inner)
|
||||
{
|
||||
public TaskCompletionSource Holding { get; } = new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
|
||||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (request.RequestUri!.AbsolutePath.StartsWith("/api/v1/frames/", StringComparison.Ordinal))
|
||||
{
|
||||
Holding.TrySetResult();
|
||||
await Task.Delay(Timeout.Infinite, cancellationToken);
|
||||
}
|
||||
return await base.SendAsync(request, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Drops the connection halfway through the first resource of <paramref name="kind"/> it serves; counts the downloads resumed with a range.</summary>
|
||||
private sealed class CutFirst(string kind, HttpMessageHandler inner) : DelegatingHandler(inner)
|
||||
{
|
||||
private int _cuts;
|
||||
private int _resumed;
|
||||
|
||||
public int Cuts => _cuts;
|
||||
public int Resumed => _resumed;
|
||||
|
||||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (request.Headers.Range is not null) Interlocked.Increment(ref _resumed);
|
||||
var response = await base.SendAsync(request, cancellationToken);
|
||||
if (!request.RequestUri!.AbsolutePath.EndsWith("/" + kind, StringComparison.Ordinal) || Interlocked.CompareExchange(ref _cuts, 1, 0) != 0)
|
||||
return response;
|
||||
var body = await response.Content.ReadAsByteArrayAsync(cancellationToken);
|
||||
var content = new StreamContent(new CutStream(body, body.Length / 2));
|
||||
foreach (var header in response.Content.Headers) content.Headers.TryAddWithoutValidation(header.Key, header.Value);
|
||||
response.Content = content;
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Records the path of every request.</summary>
|
||||
private sealed class RecordPaths(HttpMessageHandler inner) : DelegatingHandler(inner)
|
||||
{
|
||||
private readonly ConcurrentQueue<string> _paths = new();
|
||||
|
||||
public IReadOnlyCollection<string> Paths => _paths;
|
||||
|
||||
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
_paths.Enqueue(request.RequestUri!.AbsolutePath);
|
||||
return base.SendAsync(request, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Decodes every HEIF as a mid-grey 96 × 64 frame, as a native HEIF decoder would decode a real one.</summary>
|
||||
private sealed class SolidHeif : IImageDecoderProvider
|
||||
{
|
||||
public string Name => "heif-test";
|
||||
|
||||
public DecodeTier? TierFor(ImageFileFormat format) => format == ImageFileFormat.Heif ? DecodeTier.Native : null;
|
||||
|
||||
public DecodedImage? Decode(DecodeRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var image = new ImageBuffer(96, 64);
|
||||
for (var c = 0; c < 3; c++) image.Plane(c).Fill(0.2f);
|
||||
return new DecodedImage(image, DecodeTier.Native, Name, 96, 64);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Counts the node's claims the server answered.</summary>
|
||||
private sealed class CountClaims(HttpMessageHandler inner) : DelegatingHandler(inner)
|
||||
{
|
||||
private int _answered;
|
||||
|
||||
public int Answered => Volatile.Read(ref _answered);
|
||||
|
||||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
var response = await base.SendAsync(request, cancellationToken);
|
||||
if (request.RequestUri!.AbsolutePath.EndsWith("/claim", StringComparison.Ordinal)) Interlocked.Increment(ref _answered);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The first <c>cut</c> bytes, then a reset connection.</summary>
|
||||
private sealed class CutStream(byte[] data, int cut) : MemoryStream(data, 0, cut)
|
||||
{
|
||||
public override int Read(byte[] buffer, int offset, int count) => Check(base.Read(buffer, offset, count));
|
||||
|
||||
public override int Read(Span<byte> buffer) => Check(base.Read(buffer));
|
||||
|
||||
public override async ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default) =>
|
||||
Check(await base.ReadAsync(buffer, cancellationToken));
|
||||
|
||||
private static int Check(int read) => read > 0 ? read : throw new IOException("Connection reset by peer");
|
||||
}
|
||||
|
||||
private static async Task UntilAsync(Func<Task<bool>> condition, string what)
|
||||
{
|
||||
var until = DateTime.UtcNow.AddSeconds(30);
|
||||
while (!await condition())
|
||||
{
|
||||
if (DateTime.UtcNow > until) Assert.Fail("Timed out waiting for " + what);
|
||||
await Task.Delay(25);
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task<JobDto> CreateRenderAsync(TestServer server, HttpClient editor, Guid sequenceId, ExportSettings? export = null)
|
||||
{
|
||||
var sequence = (await server.Database.Sequences.GetAsync(sequenceId))!;
|
||||
var request = ProcessingJobs.Render(sequence, export ?? 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Chronos.Protocol;
|
||||
using Chronos.Protocol.Client;
|
||||
using Chronos.Server.Jobs;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.Server.Tests.Jobs;
|
||||
|
||||
[Category("server")]
|
||||
public sealed class RenderNodeTests(TestContext context)
|
||||
{
|
||||
private static readonly string HevcJob = JsonSerializer.Serialize(
|
||||
new RenderJobParameters("4K HEVC", """{"codec":"hevc","bitrate":60}""", "hevc", 3840, 2160, UseProxies: false, null), ProtocolJson.Default.RenderJobParameters);
|
||||
|
||||
[Test]
|
||||
public async Task NodesClaimWhatTheyCanEncodeAndLoseJobsWhenSilent()
|
||||
{
|
||||
var clock = new ManualTimeProvider();
|
||||
await using var server = await TestServer.StartAsync(context, o => o.NodeTimeoutSeconds = 60, s => s.AddSingleton<TimeProvider>(clock));
|
||||
var (editor, _, _) = await server.UserAsync("alberto", "editor", renderNode: true);
|
||||
var frame = await Uploads.UploadAsync(editor, Uploads.Photo(5000, 51), "IMG_0001.CR3");
|
||||
var job = await JobApiTests.CreateAsync(editor, "render", frame.SequenceId, HevcJob);
|
||||
|
||||
var studio = await RegisterAsync(editor, "studio-pc", "hevc", 8192);
|
||||
var laptop = await RegisterAsync(editor, "laptop", "h264", 4096);
|
||||
var spare = await RegisterAsync(editor, "spare-pc", "HEVC", 0);
|
||||
using (var none = await editor.PostAsync($"/api/v1/nodes/{laptop.Id}/claim", null)) await none.ExpectAsync(HttpStatusCode.NoContent);
|
||||
|
||||
ClaimedJob claimed;
|
||||
using (var claim = await editor.PostAsync($"/api/v1/nodes/{studio.Id}/claim", null))
|
||||
{
|
||||
await claim.ExpectAsync(HttpStatusCode.OK);
|
||||
claimed = await claim.ReadAsync(ProtocolJson.Default.ClaimedJob);
|
||||
}
|
||||
Assert.Equal((job.Id, frame.SequenceId, "running"), (claimed.Job.Id, claimed.SequenceId, claimed.Job.State));
|
||||
Assert.Equal(frame.FrameId, claimed.Frames.Single().Id);
|
||||
Assert.Equal(studio.Id.ToString(), claimed.Job.NodeId);
|
||||
using (var second = await editor.PostAsync($"/api/v1/nodes/{spare.Id}/claim", null)) await second.ExpectAsync(HttpStatusCode.NoContent);
|
||||
|
||||
using (var progress = await editor.PostAsJsonAsync($"/api/v1/nodes/{studio.Id}/jobs/{job.Id}/progress", new NodeProgress(120, 3600, 40, "encoding"),
|
||||
ProtocolJson.Default.NodeProgress))
|
||||
await progress.ExpectAsync(HttpStatusCode.NoContent);
|
||||
Assert.Equal(120L, (await JobApiTests.GetAsync(editor, job.Id)).ProgressDone);
|
||||
|
||||
// studio-pc goes silent; the others keep heart-beating.
|
||||
clock.Advance(TimeSpan.FromSeconds(90));
|
||||
foreach (var alive in new[] { laptop, spare })
|
||||
using (var beat = await editor.PostAsync($"/api/v1/nodes/{alive.Id}/heartbeat", null)) await beat.ExpectAsync(HttpStatusCode.NoContent);
|
||||
await server.Services.GetRequiredService<RenderNodeMonitor>().SweepAsync(context.Cancellation);
|
||||
|
||||
var requeued = await JobApiTests.GetAsync(editor, job.Id);
|
||||
Assert.Equal("queued", requeued.State);
|
||||
Assert.Contains("studio-pc stopped responding", requeued.LogTail);
|
||||
using (var nodes = await editor.GetAsync("/api/v1/nodes"))
|
||||
{
|
||||
var states = (await nodes.ReadAsync(ProtocolJson.Default.ListRenderNodeDto)).ToDictionary(n => n.ClientName, n => n.State);
|
||||
Assert.Equal(("offline", "idle"), (states["studio-pc"], states["laptop"]));
|
||||
}
|
||||
using (var late = await editor.PostAsJsonAsync($"/api/v1/nodes/{studio.Id}/jobs/{job.Id}/progress", new NodeProgress(200, 3600, 40, null),
|
||||
ProtocolJson.Default.NodeProgress))
|
||||
await late.ExpectErrorAsync(HttpStatusCode.Conflict, "job_not_assigned");
|
||||
|
||||
using (var reassigned = await editor.PostAsync($"/api/v1/nodes/{spare.Id}/claim", null))
|
||||
{
|
||||
var again = await reassigned.ReadAsync(ProtocolJson.Default.ClaimedJob);
|
||||
Assert.Equal((job.Id, 2), (again.Job.Id, again.Job.Attempts));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task EachEncoderTakesOnlyJobsWithinItsOwnSizeLimit()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context);
|
||||
var (editor, _, _) = await server.UserAsync("alberto", "editor", renderNode: true);
|
||||
var sequence = await JobApiTests.CreateSequenceAsync(editor);
|
||||
// The software H.264 encoder stops at 4096 px although the node's MJPEG encoder writes far larger frames.
|
||||
using var registered = await editor.PostAsJsonAsync("/api/v1/nodes/register", new RegisterNodeRequest("studio-pc",
|
||||
[new NodeEncoder("h264", "H.264 Encoder MFT", false, false, 4096, 2304), new NodeEncoder("mjpeg", "Managed MJPEG", false, false, 65535, 65535)],
|
||||
65535, 65535), ProtocolJson.Default.RegisterNodeRequest);
|
||||
var node = await registered.ReadAsync(ProtocolJson.Default.RenderNodeDto);
|
||||
Assert.Equal((4096, 2304), (node.Encoders[0].MaxWidth, node.Encoders[0].MaxHeight));
|
||||
|
||||
await JobApiTests.CreateAsync(editor, "render", sequence, H264Job(6144, 3456));
|
||||
using (var none = await editor.PostAsync($"/api/v1/nodes/{node.Id}/claim", null)) await none.ExpectAsync(HttpStatusCode.NoContent);
|
||||
var uhd = await JobApiTests.CreateAsync(editor, "render", sequence, H264Job(3840, 2160));
|
||||
using var claim = await editor.PostAsync($"/api/v1/nodes/{node.Id}/claim", null);
|
||||
Assert.Equal(uhd.Id, (await claim.ReadAsync(ProtocolJson.Default.ClaimedJob)).Job.Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheOutputUploadBecomesARenderAndFinishesTheJob()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context, o => o.ChunkSizeBytes = 64 * 1024);
|
||||
var (editor, _, token) = await server.UserAsync("alberto", "editor", renderNode: true);
|
||||
var frame = await Uploads.UploadAsync(editor, Uploads.Photo(5000, 52), "IMG_0001.CR3");
|
||||
var job = await JobApiTests.CreateAsync(editor, "render", frame.SequenceId, HevcJob);
|
||||
|
||||
using var client = new ChronosClient(server.HttpBase, new CertificatePinning([]), "studio-pc") { Token = token };
|
||||
var node = await client.RegisterNodeAsync(new RegisterNodeRequest("studio-pc", [new NodeEncoder("hevc", "NVENC HEVC", true, true)], 8192, 8192));
|
||||
var claimed = Assert.NotNull(await client.ClaimAsync(node.Id));
|
||||
await client.ReportNodeProgressAsync(node.Id, claimed.Job.Id, new NodeProgress(3600, 3600, 50, "muxing"));
|
||||
|
||||
var output = Path.Combine(context.CreateTempDirectory("render"), "Harbour sunset - 4K HEVC.mp4");
|
||||
var video = Uploads.Photo(150_000, 53);
|
||||
await File.WriteAllBytesAsync(output, video);
|
||||
var render = await client.UploadRenderResultAsync(node.Id, job.Id, output,
|
||||
new RenderResultRequest(Path.GetFileName(output), video.Length, Uploads.Sha(video), "4K HEVC", "hevc", 3840, 2160, 25, 144));
|
||||
Assert.Equal(("4K HEVC", "studio-pc", (long)video.Length), (render.PresetName, render.ProducedBy, render.Bytes));
|
||||
|
||||
var done = await JobApiTests.GetAsync(editor, job.Id);
|
||||
Assert.Equal("done", done.State);
|
||||
var sequence = (await server.Database.Sequences.GetAsync(frame.SequenceId))!;
|
||||
Assert.Equal(1, sequence.RenderedCount);
|
||||
var file = Path.Combine(server.Options.ArchivePath, sequence.Folder, "exports", "Harbour sunset - 4K HEVC.mp4");
|
||||
await Http.BytesEqualAsync(video, File.ReadAllBytesAsync(file));
|
||||
using var renders = await editor.GetAsync($"/api/v1/sequences/{sequence.Id}/renders");
|
||||
Assert.Equal(render.Id, (await renders.ReadAsync(ProtocolJson.Default.ListRenderDto)).Single().Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NodesReportFailuresAndNeedTheRight()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context);
|
||||
var (editor, _, _) = await server.UserAsync("alberto", "editor", renderNode: true);
|
||||
var (plain, _, _) = await server.UserAsync("giulia", "editor");
|
||||
var sequence = await JobApiTests.CreateSequenceAsync(editor);
|
||||
var job = await JobApiTests.CreateAsync(editor, "render", sequence, HevcJob);
|
||||
var node = await RegisterAsync(editor, "studio-pc", "hevc", 8192);
|
||||
using (var claim = await editor.PostAsync($"/api/v1/nodes/{node.Id}/claim", null)) await claim.ExpectAsync(HttpStatusCode.OK);
|
||||
using (var failed = await editor.PostAsJsonAsync($"/api/v1/nodes/{node.Id}/jobs/{job.Id}/failed", new NodeJobFailure("NVENC session limit reached"),
|
||||
ProtocolJson.Default.NodeJobFailure))
|
||||
await failed.ExpectAsync(HttpStatusCode.NoContent);
|
||||
var state = await JobApiTests.GetAsync(editor, job.Id);
|
||||
Assert.Equal(("failed", "NVENC session limit reached"), (state.State, state.Error));
|
||||
|
||||
using var refused = await plain.PostAsJsonAsync("/api/v1/nodes/register", new RegisterNodeRequest("giulia-pc", [new NodeEncoder("hevc", "QSV", true, false)], 0, 0),
|
||||
ProtocolJson.Default.RegisterNodeRequest);
|
||||
await refused.ExpectErrorAsync(HttpStatusCode.Forbidden, "forbidden");
|
||||
using var foreign = await plain.PostAsync($"/api/v1/nodes/{node.Id}/heartbeat", null);
|
||||
await foreign.ExpectErrorAsync(HttpStatusCode.Forbidden, "forbidden");
|
||||
}
|
||||
|
||||
private static string H264Job(int width, int height) => JsonSerializer.Serialize(
|
||||
new RenderJobParameters("H.264", """{"preset":{"isAuto":false,"manual":"4k-h264"}}""", "h264", width, height, UseProxies: false, null),
|
||||
ProtocolJson.Default.RenderJobParameters);
|
||||
|
||||
private static async Task<RenderNodeDto> RegisterAsync(HttpClient client, string name, string codec, int maxWidth)
|
||||
{
|
||||
using var response = await client.PostAsJsonAsync("/api/v1/nodes/register",
|
||||
new RegisterNodeRequest(name, [new NodeEncoder(codec, codec.ToUpperInvariant() + " encoder", true, false)], maxWidth, maxWidth), ProtocolJson.Default.RegisterNodeRequest);
|
||||
await response.ExpectAsync(HttpStatusCode.OK);
|
||||
return await response.ReadAsync(ProtocolJson.Default.RenderNodeDto);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user