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>
71 lines
2.9 KiB
TypeScript
71 lines
2.9 KiB
TypeScript
import { mkdir, rm, writeFile } from "node:fs/promises";
|
|
import { expect, it } from "vitest";
|
|
|
|
import { ApktoolCommandCleanup } from "../../../src/apktool/ApktoolCommandCleanup.js";
|
|
import { inspectApktoolClient } from "../../../src/apktool/ApktoolConfiguration.js";
|
|
import { createApktoolProcessFixture } from "../../fixtures/apktoolProcessTree.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
import { observePosixProcess } from "../../support/process/observePosixProcess.js";
|
|
|
|
const VERSION_PROBE_DEADLINE_MS = 20_000;
|
|
|
|
it
|
|
.skipIf(process.platform === "win32")
|
|
.each(["malformed", "unreadable"] as const)(
|
|
"retains fixture cleanup ownership when its published marker becomes %s",
|
|
async (failure) => {
|
|
const root = await createTestTempDirectory("rea-apktool-marker-failure-");
|
|
const fixture = await createApktoolProcessFixture(root, "probe");
|
|
await expect(fixture.readMarker()).resolves.toBeUndefined();
|
|
const commands = new ApktoolCommandCleanup();
|
|
const controller = new AbortController();
|
|
const probeStarted = performance.now();
|
|
const probe = inspectApktoolClient(
|
|
{ command: fixture.command, commandSource: "environment" },
|
|
commands,
|
|
{ signal: controller.signal, environment: process.env },
|
|
).catch((cause: unknown) => cause);
|
|
try {
|
|
await expect
|
|
.poll(async () => (await fixture.readMarker())?.ready, {
|
|
interval: 25,
|
|
})
|
|
.toBe(true);
|
|
const marker = await fixture.readMarker();
|
|
if (marker === undefined) throw new Error("Fixture marker disappeared");
|
|
const pids = [marker.rootPid, marker.childPid];
|
|
expect(await Promise.all(pids.map(observePosixProcess))).toEqual([
|
|
expect.objectContaining({ kind: "running" }),
|
|
expect.objectContaining({ kind: "running" }),
|
|
]);
|
|
if (failure === "malformed") {
|
|
await writeFile(fixture.markerPath, "not-json");
|
|
} else {
|
|
await rm(fixture.markerPath);
|
|
await mkdir(fixture.markerPath);
|
|
}
|
|
await expect(fixture.readMarker()).rejects.toThrow();
|
|
// No cancellation has run: fallback teardown must use the last valid
|
|
// token owner even when the current marker cannot be read or parsed.
|
|
await expect(fixture.cleanup()).rejects.toThrow();
|
|
await expect
|
|
.poll(
|
|
async () =>
|
|
(await Promise.all(pids.map(observePosixProcess))).every(
|
|
({ kind }) => kind !== "running",
|
|
),
|
|
{ interval: 25 },
|
|
)
|
|
.toBe(true);
|
|
// The still-running version probe would also stop them at its own
|
|
// deadline (ApktoolConfiguration: 20 s); fixture teardown must be first.
|
|
expect(performance.now() - probeStarted).toBeLessThan(
|
|
VERSION_PROBE_DEADLINE_MS,
|
|
);
|
|
} finally {
|
|
controller.abort();
|
|
await fixture.cleanup([probe, commands.close()]);
|
|
}
|
|
},
|
|
);
|