mirror of
https://github.com/morluto/rea.git
synced 2026-11-14 18:52:48 +00:00
Vitest's expect.poll and vi.waitFor stop after one second by default, a host-speed guess that the project's deadline policy does not see. Under hosted-CI load, kunaProjectConcurrency failed that way twice on unrelated PRs. Another 256 waits relied on the default, and 97 passed literals picked to fit some host. Waits now take as long as their test may run, less the reporting reserve that children already keep. Each Vitest project sets expect.poll's default, and the new waitFor in tests/support/testWait.ts replaces vi.waitFor. Fixture readiness waits (awaitAcknowledgement and the provider process waits) default to the same deadline, and their host-speed literal arguments are removed. One remainingTestDeadline owns the arithmetic for both children and waits. Ten waits whose short timeout was the real check now assert it directly (Kuna version probe, Cutter discovery, doctor and Inspector cancellation, apktool fixture teardown, JADX disconnect): settlement before the production deadline that would otherwise also satisfy the wait, or a deadline pinned beyond every test deadline. The rea/project-wait-deadline lint rule rejects vi.waitFor and explicit expect.poll timeouts. The testing guide and the CI tests audit skill now document the policy. Co-Authored-By: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
44 lines
1.7 KiB
TypeScript
44 lines
1.7 KiB
TypeScript
import { expect, inject, it } from "vitest";
|
|
import {
|
|
COVERAGE_DEADLINE_SCALE,
|
|
HOSTED_RUNNER_DEADLINE_SCALE,
|
|
remainingTestDeadline,
|
|
TEST_DEADLINE_MS,
|
|
} from "../support/testDeadlines.js";
|
|
import { waitFor } from "../support/testWait.js";
|
|
|
|
// Longer than Vitest's one-second wait default, so these probes fail if the
|
|
// project deadline policy stops owning wait deadlines.
|
|
const PAST_VITEST_WAIT_DEFAULT_MS = 1_200;
|
|
|
|
it("applies the source project deadline, scaled by coverage and hosted runners", ({
|
|
task,
|
|
}) => {
|
|
const scale = inject("testDeadlineScale");
|
|
const coverage = [1, COVERAGE_DEADLINE_SCALE];
|
|
const hosted = [1, HOSTED_RUNNER_DEADLINE_SCALE];
|
|
expect(coverage.flatMap((c) => hosted.map((h) => c * h))).toContain(scale);
|
|
expect(task.timeout).toBe(TEST_DEADLINE_MS.source * scale);
|
|
});
|
|
|
|
it("derives a wait or child deadline from the test deadline, keeping a reporting reserve", () => {
|
|
expect(remainingTestDeadline(120_000, 0)).toBe(108_000);
|
|
expect(remainingTestDeadline(30_000, 20_000)).toBe(5_000);
|
|
// The reserve never drops below five seconds, nor the deadline below one.
|
|
expect(remainingTestDeadline(8_000, 0)).toBe(3_000);
|
|
expect(remainingTestDeadline(8_000, 7_500)).toBe(1_000);
|
|
expect(remainingTestDeadline(0, 0)).toBeUndefined();
|
|
});
|
|
|
|
it("bounds expect.poll by the project deadline", async () => {
|
|
const ready = performance.now() + PAST_VITEST_WAIT_DEFAULT_MS;
|
|
await expect.poll(() => performance.now() >= ready).toBe(true);
|
|
});
|
|
|
|
it("bounds waitFor by its test's deadline", async () => {
|
|
const ready = performance.now() + PAST_VITEST_WAIT_DEFAULT_MS;
|
|
await waitFor(() => {
|
|
if (performance.now() < ready) throw new Error("not ready yet");
|
|
});
|
|
});
|