From 4baddaab7fa7f724724134ac21ab0378db40200a Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Fri, 17 Oct 2025 21:51:11 +0200 Subject: [PATCH] Add test verifying cancellation before processing starts --- FFMpegCore.Test/VideoTest.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/FFMpegCore.Test/VideoTest.cs b/FFMpegCore.Test/VideoTest.cs index 7946552..5921a6e 100644 --- a/FFMpegCore.Test/VideoTest.cs +++ b/FFMpegCore.Test/VideoTest.cs @@ -1043,6 +1043,28 @@ public class VideoTest Assert.ThrowsExactly(() => task.ProcessSynchronously()); } + [TestMethod] + [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] + public void Video_Cancel_CancellationToken_Before_Throws() + { + using var outputFile = new TemporaryFile("out.mp4"); + + var cts = new CancellationTokenSource(); + + 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)) + .CancellableThrough(cts.Token); + + Assert.ThrowsExactly(() => task.ProcessSynchronously()); + } + [TestMethod] [Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)] public async Task Video_Cancel_CancellationToken_Async_With_Timeout()