Four App tests switched the process-wide UI language inside parallel classes, so another class's English assertion, or its constructor's reset to English, could land in the middle of them; they now live in the serial ArchiveLanguageTests and ImportLanguageTests. The App and Core test programs fail a test that leaves English outside a serial class at the switch, through the new TestContext.Current and TestContext.IsSerial. The FrameWindow cancellation test counted unobserved task exceptions while other classes ran beside it; it moves to the serial FrameWindowIsolationTests, and both unobserved-exception tests drain the finalizer queue before they start counting. The runner unwrapped TargetInvocationException only around the test method: a skip or an assertion thrown by a test class constructor or field initializer was reported as a failure reading "Exception has been thrown by the target of an invocation". Constructors are unwrapped the same way now. TestRunner.Discover(Type) and ExecuteAsync are public, so Tools.Tests checks the runner with nested fixtures. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
73 lines
3.2 KiB
C#
73 lines
3.2 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()
|
|
{
|
|
// Faulted tasks the earlier tests left for the finalizer are reported now, before this test starts counting.
|
|
GC.Collect();
|
|
GC.WaitForPendingFinalizers();
|
|
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);
|
|
}
|
|
}
|