From cdf2dd5b659c281b4d6e002537056e69943303ac Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Mon, 27 Oct 2025 21:01:36 +0100 Subject: [PATCH] Refine unit tests for cancellation --- FFMpegCore.Test/VideoTest.cs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/FFMpegCore.Test/VideoTest.cs b/FFMpegCore.Test/VideoTest.cs index b0a85aa..cb239c6 100644 --- a/FFMpegCore.Test/VideoTest.cs +++ b/FFMpegCore.Test/VideoTest.cs @@ -1122,13 +1122,12 @@ public class VideoTest [TestMethod] [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] - public void Video_Cancel_CancellationToken_Before_Throws() + public void Video_Cancel_CancellationToken_BeforeProcessing_Throws() { using var outputFile = new TemporaryFile("out.mp4"); using var cts = CancellationTokenSource.CreateLinkedTokenSource(TestContext.CancellationToken); - cts.Cancel(); var task = FFMpegArguments .FromFileInput("testsrc2=size=320x240[out0]; sine[out1]", false, args => args .WithCustomArgument("-re") @@ -1139,8 +1138,29 @@ public class VideoTest .WithSpeedPreset(Speed.VeryFast)) .CancellableThrough(cts.Token); - Assert.ThrowsExactly(() => task.CancellableThrough(TestContext.CancellationToken) - .ProcessSynchronously()); + cts.Cancel(); + Assert.ThrowsExactly(() => task.ProcessSynchronously()); + } + + [TestMethod] + [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] + public void Video_Cancel_CancellationToken_BeforePassing_Throws() + { + using var outputFile = new TemporaryFile("out.mp4"); + + using var cts = CancellationTokenSource.CreateLinkedTokenSource(TestContext.CancellationToken); + cts.Cancel(); + + var task = FFMpegArguments + .FromFileInput("testsrc2=size=320x240[out0]; sine[out1]", false, args => args + .WithCustomArgument("-re") + .ForceFormat("lavfi")) + .OutputToFile(outputFile, false, opt => opt + .WithAudioCodec(AudioCodec.Aac) + .WithVideoCodec(VideoCodec.LibX264) + .WithSpeedPreset(Speed.VeryFast)); + + Assert.ThrowsExactly(() => task.CancellableThrough(cts.Token)); } [TestMethod]