From d54c9d8920493bf1046546b5bf5c2e9f8292c557 Mon Sep 17 00:00:00 2001 From: Project516 <138796702+Project516@users.noreply.github.com> Date: Sun, 4 Oct 2026 17:50:31 -0500 Subject: [PATCH] test: time out a job that cannot finish first instead of racing a 1ms timeout --- tests/ffmpeg-core.test.js | 5 +++-- tests/ffmpeg-node.test.mjs | 10 +++------- tests/ffmpeg.test.js | 3 ++- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/tests/ffmpeg-core.test.js b/tests/ffmpeg-core.test.js index 82b39659e3b..9c99d04662b 100644 --- a/tests/ffmpeg-core.test.js +++ b/tests/ffmpeg-core.test.js @@ -149,8 +149,9 @@ describe(genName("setTimeout()"), () => { }); it("should timeout", () => { - core.setTimeout(1); // timeout after 1ms - expect(core.exec("-i", "video.mp4", "video.avi")).to.equal(1); + core.setTimeout(50); + // Long enough that it cannot finish first, however fast the machine is. + expect(core.exec("-f", "lavfi", "-i", "testsrc=size=320x240:rate=30:duration=3600", "-f", "null", "-")).to.equal(1); }); }); diff --git a/tests/ffmpeg-node.test.mjs b/tests/ffmpeg-node.test.mjs index 6b702e41c2c..f34926a6420 100644 --- a/tests/ffmpeg-node.test.mjs +++ b/tests/ffmpeg-node.test.mjs @@ -233,16 +233,12 @@ describe(genName("FFmpeg"), function () { }); it("stops exec() after the given timeout", async () => { - await ffmpeg.writeFile( - "timeout.mp4", - b64ToUint8Array(VIDEO_1S_MP4) - ); + // Long enough that it cannot finish before the timeout. const ret = await ffmpeg.exec( - ["-i", "timeout.mp4", "timeout.avi"], - 1 // 1ms, well under the time a transcode takes + ["-f", "lavfi", "-i", "testsrc=size=320x240:rate=30:duration=3600", "-f", "null", "-"], + 50 ); expect(ret).to.equal(1); - await ffmpeg.deleteFile("timeout.mp4"); }); }); diff --git a/tests/ffmpeg.test.js b/tests/ffmpeg.test.js index 449d02d94ed..362a8dc74e1 100644 --- a/tests/ffmpeg.test.js +++ b/tests/ffmpeg.test.js @@ -148,7 +148,8 @@ describe(genName("FFmpeg.exec()"), function () { }); it("should stop if timeout", async () => { - const ret = await ffmpeg.exec(["-i", "video.mp4", "video.avi"], 1); + // Long enough that it cannot finish before the timeout. + const ret = await ffmpeg.exec(["-f", "lavfi", "-i", "testsrc=size=320x240:rate=30:duration=3600", "-f", "null", "-"], 50); expect(ret).to.equal(1); });