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>
35 lines
1.4 KiB
TypeScript
35 lines
1.4 KiB
TypeScript
import { inject, TestRunner, vi } from "vitest";
|
|
|
|
import { remainingTestDeadline, TEST_DEADLINE_MS } from "./testDeadlines.js";
|
|
|
|
/** Options for {@link waitFor}; the test deadline policy owns the timeout. */
|
|
export interface WaitForOptions {
|
|
readonly interval?: number;
|
|
}
|
|
|
|
/**
|
|
* Deadline for a wait: as long as its test may run, less the reporting reserve,
|
|
* matching the project's `expect.poll` policy. Outside a test, as in
|
|
* `beforeAll`, it uses the shortest project deadline. A wait that starts late
|
|
* may outlast the test, which then fails with Vitest's own timeout.
|
|
*/
|
|
export const testWaitDeadline = (): number => {
|
|
const testDeadlineMs =
|
|
TestRunner.getCurrentTest()?.timeout ??
|
|
TEST_DEADLINE_MS.source * inject("testDeadlineScale");
|
|
return remainingTestDeadline(testDeadlineMs, 0) ?? TEST_DEADLINE_MS.source;
|
|
};
|
|
|
|
/**
|
|
* `vi.waitFor` bounded by {@link testWaitDeadline} rather than Vitest's
|
|
* one-second default, so a slow host neither fails a correct test nor needs a
|
|
* literal timeout. Assert elapsed time explicitly, or order the condition
|
|
* before a release gate, when promptness is the behavior under test.
|
|
*/
|
|
export const waitFor = <T>(
|
|
callback: () => T | Promise<T>,
|
|
options: WaitForOptions = {},
|
|
): Promise<T> =>
|
|
// oxlint-disable-next-line rea/project-wait-deadline -- the owning helper.
|
|
vi.waitFor(callback, { ...options, timeout: testWaitDeadline() });
|