mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-23 11:29:54 +00:00
fix(producer): cancelling a render stops its compile (#8242)
* test(producer): compile-time remote downloads are capped, timed and stop with the render * fix(producer): cap compile-time remote downloads, give them one deadline and stop them on cancel * test(producer): size-limit tests stay under the remote download cap * test(producer): count a refetched bundled script; start the deadline at the first download * test(producer): export the download deadline so its test reads the real value * fix(producer): count every downloaded script and start the download deadline at the first one * test(producer): read the host's script copy once however many tags name it * fix(producer): read a bundled script once per address; document the compile download limits * test(producer): size the shared-font test from the 64 MB limit so it reaches it * test(producer): cancel a render while it compiles * fix(producer): cancelling a render stops its compile
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import { afterEach, expect, it, vi } from "vitest";
|
||||
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { resolveConfig } from "@hyperframes/engine";
|
||||
import { createRenderJob, executeRenderJob } from "./renderOrchestrator.js";
|
||||
|
||||
// Entry: executeRenderJob. The compile stage stands in for remote downloads that never answer: it settles only
|
||||
// when the signal it was given aborts.
|
||||
const compile = vi.hoisted(() => ({ signals: [] as Array<AbortSignal | undefined> }));
|
||||
vi.mock("./render/stages/compileStage.js", () => ({
|
||||
runCompileStage: ({ abortSignal }: { abortSignal?: AbortSignal }) => {
|
||||
compile.signals.push(abortSignal);
|
||||
return new Promise((_, reject) =>
|
||||
abortSignal?.addEventListener("abort", () => reject(abortSignal.reason), { once: true }),
|
||||
);
|
||||
},
|
||||
}));
|
||||
vi.mock("./render/shared.js", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("./render/shared.js")>()),
|
||||
createMemorySampler: () => ({
|
||||
peakRssBytes: () => 0,
|
||||
peakHeapUsedBytes: () => 0,
|
||||
stop: () => {},
|
||||
}),
|
||||
}));
|
||||
|
||||
const dirs: string[] = [];
|
||||
afterEach(() => {
|
||||
compile.signals.length = 0;
|
||||
for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
// fails without the fix: the compile stage got no signal, so a cancelled render waited out its downloads.
|
||||
it("cancelling a render during compile stops the compile and settles the render", async () => {
|
||||
const root = mkdtempSync(join(tmpdir(), "hf-compile-cancel-"));
|
||||
dirs.push(root);
|
||||
writeFileSync(join(root, "index.html"), "<div></div>");
|
||||
const job = createRenderJob({
|
||||
fps: 30,
|
||||
quality: "draft",
|
||||
format: "mp4",
|
||||
hdrMode: "force-sdr",
|
||||
producerConfig: resolveConfig({ enablePageSideCompositing: false }),
|
||||
logger: { info() {}, warn() {}, error() {}, debug() {} },
|
||||
});
|
||||
const cancel = new AbortController();
|
||||
const render = executeRenderJob(job, root, join(root, "out.mp4"), undefined, cancel.signal);
|
||||
|
||||
await vi.waitFor(() => expect(compile.signals).toHaveLength(1));
|
||||
expect(compile.signals[0]).toBeInstanceOf(AbortSignal);
|
||||
cancel.abort();
|
||||
await expect(render).rejects.toThrow();
|
||||
expect(compile.signals[0]?.aborted).toBe(true);
|
||||
});
|
||||
@@ -3351,6 +3351,7 @@ async function executeRenderPipeline(input: {
|
||||
needsAlpha,
|
||||
log,
|
||||
assertNotAborted,
|
||||
abortSignal: executionSignal,
|
||||
variables: job.config.variables,
|
||||
pageMotionBlur: job.config.pageMotionBlur,
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user