Files
Chronos/tests/Titano.Core.Tests/Render/RenderIsolationTests.cs
T
Claude 3780105f36 feat(render): preparation pass, render geometry and pipeline
RenderPreparation measures (or reuses cached) luminance, colour, region
and camera-path series and turns them into per-frame corrections.
RenderPipeline renders planned frames through exposure, one geometry
resample, flow synthesis, motion blur, stacking and the knee, overlapping
encoding with processing; cancellation and failures leave no output and
no unobserved exceptions. Batch renders share one preparation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
2026-10-02 11:09:02 +00:00

70 lines
3.0 KiB
C#

using Titano.Core.Render;
using Titano.Core.Video;
using Titano.Testing;
using static Titano.Core.Tests.Render.RenderFixture;
namespace Titano.Core.Tests.Render;
/// <summary>Process-wide observations (unobserved task exceptions, managed heap) that must not overlap other tests.</summary>
[Serial]
public sealed class RenderIsolationTests
{
private readonly TestContext _context;
public RenderIsolationTests(TestContext context) => _context = context;
[Test]
public async Task FailuresLeaveNoUnobservedTaskExceptions()
{
var unobserved = 0;
void Handler(object? sender, UnobservedTaskExceptionEventArgs e) => Interlocked.Increment(ref unobserved);
TaskScheduler.UnobservedTaskException += Handler;
try
{
var dir = _context.CreateTempDirectory();
var capture = new CapturingEncoderProvider("capture", new EncoderCapability(VideoCodec.PngSequence, "Capture", false, 4096, 4096, true))
{
FailAt = (2, new InvalidDataException("encoder broke")),
};
for (var i = 0; i < 3; i++)
{
await Assert.ThrowsAsync<InvalidDataException>(() => Pipeline(capture).RenderAsync(Input(Source()), Target(dir, Preset("png-sequence"))));
var input = Input(Source()) with { Source = new FailingSource(Source(), failAt: 3 + i) };
await Assert.ThrowsAsync<IOException>(() => Pipeline().RenderAsync(input, Target(dir, Preset("gif-preview"))));
}
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
Assert.Equal(0, unobserved);
Assert.Empty(Directory.GetFileSystemEntries(dir));
}
finally
{
TaskScheduler.UnobservedTaskException -= Handler;
}
}
/// <summary>BRIEF §20.4: peak memory does not depend on the sequence length (live managed heap sampled while rendering).</summary>
[Test]
public async Task MemoryDoesNotGrowWithSequenceLength()
{
async Task<long> PeakAsync(int frames)
{
var dir = _context.CreateTempDirectory();
long peak = 0;
var progress = new Sink<RenderProgress>(p =>
{
if (p.Stage == RenderStage.Rendering && p.Done % 8 == 0) peak = Math.Max(peak, GC.GetTotalMemory(forceFullCollection: true));
});
var project = Plain with { Exposure = new Titano.Core.Project.ExposureSettings { Deflicker = new Titano.Core.Project.Auto<bool>().WithManual(true) } };
await Pipeline().RenderAsync(Input(Source(frames), project), Target(dir, Preset("mjpeg-avi")), progress: progress, cancellationToken: _context.Cancellation);
return peak;
}
await PeakAsync(16);
var shortPeak = await PeakAsync(48);
var longPeak = await PeakAsync(192);
_context.Log($"peak live heap: 48 frames {shortPeak / 1024} KiB, 192 frames {longPeak / 1024} KiB");
Assert.Less(longPeak - shortPeak, 2 << 20);
}
}