test(producer): pay the first render's start-up cost before the stall and frame-window tests (#7503)

This commit is contained in:
Miguel Ángel
2026-11-12 17:38:12 +00:00
committed by GitHub
parent bfd3fe644b
commit d1a366b42f
2 changed files with 36 additions and 7 deletions
@@ -1,4 +1,4 @@
import { afterEach, beforeEach, expect, it, onTestFinished, vi } from "vitest";
import { afterEach, beforeAll, beforeEach, expect, it, onTestFinished, vi } from "vitest";
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
@@ -253,10 +253,7 @@ async function timed<T>(step: string, run: () => Promise<T>): Promise<T> {
spent.set(step, (spent.get(step) ?? 0) + performance.now() - started);
}
}
beforeEach(() => {
spent.clear();
testStarted = performance.now();
budgetRanOut = 0;
function resetCapture(): void {
capture.scripts = [];
capture.calls = 0;
capture.retriedWithWorkers = [];
@@ -265,6 +262,26 @@ beforeEach(() => {
capture.workerCount = 4;
capture.blocked = 0;
capture.probeMs = 0;
}
// A worker's first render pays a one-time start-up cost: tens of ms on an idle host, up to 6 s on a loaded CI
// runner. One finished render here pays it outside the tests, so each test's 5 s covers only its own rule.
beforeAll(async () => {
resetCapture();
vi.useFakeTimers({
toFake: ["setTimeout", "clearTimeout", "setInterval", "clearInterval", "Date"],
});
capture.scripts = [{ firstFrameAfterMs: 1_000, frameEveryMs: 1_000 }];
const outcome = startRender();
await runFor(60_000, outcome);
await settled(outcome);
vi.useRealTimers();
for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true });
});
beforeEach(() => {
spent.clear();
testStarted = performance.now();
budgetRanOut = 0;
resetCapture();
vi.useFakeTimers({
toFake: ["setTimeout", "clearTimeout", "setInterval", "clearInterval", "Date"],
});
@@ -1,4 +1,4 @@
import { afterEach, beforeEach, expect, it, vi } from "vitest";
import { afterEach, beforeAll, beforeEach, expect, it, vi } from "vitest";
import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
@@ -265,6 +265,9 @@ beforeEach(() => {
state.folderAtNextStage = [];
state.logs = [];
state.stages = [];
stubRenderFlags();
});
function stubRenderFlags(): void {
vi.stubEnv("HF_SEGMENTED_CAPTURE", "true");
vi.stubEnv("HF_VIDEO_FRAME_WINDOW", "true");
vi.stubEnv("PRODUCER_EXPERIMENTAL_FAST_CAPTURE", "");
@@ -272,7 +275,7 @@ beforeEach(() => {
vi.stubEnv("HF_DE_PARALLEL_ROUTER", "false");
vi.stubEnv("HF_DE_PARALLEL_MIN_MEM_MB", "0");
vi.stubEnv("HF_DE_SINGLE_MIN_FRAMES", "900");
});
}
afterEach(() => {
vi.unstubAllEnvs();
for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true });
@@ -300,6 +303,15 @@ function render(config: Partial<Parameters<typeof createRenderJob>[0]> = {}): Pr
});
}
// A worker's first render pays a one-time start-up cost: tens of ms on an idle host, up to 6 s on a loaded CI
// runner. One render here pays it outside the tests, so each test's 5 s covers only its own rule.
beforeAll(async () => {
stubRenderFlags();
await render().catch(() => undefined);
vi.unstubAllEnvs();
for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true });
});
it("a segmented render with the flag on defers the long video and windows its frames", async () => {
await expect(render()).rejects.toThrow(REACHED);
expect(state.deferRequests).toEqual([true]);