Files
reverse-engineering-anything/tests/processOwnershipRunner.ts
T
morluto 6bcec126c7 test(adb): link stub executables to one launched dispatcher (#15698)
* test(adb): link stub executables to one launched dispatcher

macOS checks every newly written executable on its first launch, one file
at a time for the whole host (about 150 ms each; 50 fresh stubs launched
together took 9 s). The ADB tests wrote a fresh fake adb (and Node.js tool
shims) per test, so under parallel load the first launch waited behind
every other test's stubs inside the provider's 10 s adb version probe
deadline or the test's own deadline.

writeShellStub hard-links each stub to one dispatcher the test process has
already launched; the dispatcher sources the stub's script with the stub's
own $0 and arguments. AdbProvider.test.ts drops from 38 s to 12 s alone.

* test(adb): remove the stub dispatcher at worker teardown

Forked Vitest workers skip process exit hooks, so the dispatcher
directory leaked. The test runner now removes it through the worker
cleanup it already uses for the process ownership host.
2026-12-02 00:28:46 +00:00

30 lines
1.3 KiB
TypeScript

import { TestRunner } from "vitest";
import type { ProcessOwnershipHost } from "../src/process/ProcessOwnership.js";
/**
* Retire each isolated graph's native cache and shell stub dispatcher when its
* test worker stops. Forked workers do not run `process.on("exit")` hooks.
*/
export default class ProcessOwnershipRunner extends TestRunner {
readonly #registeredHosts = new WeakSet<ProcessOwnershipHost>();
readonly #registeredStubOwners = new WeakSet<() => Promise<void>>();
async onBeforeRunFiles(): Promise<void> {
const { systemProcessOwnershipHost } =
await import("../src/process/ProcessOwnershipObservation.js");
const { closeShellStubDispatcher } =
await import("./fixtures/shellStub.js");
if (this.onCleanupWorkerContext === undefined)
throw new Error("The test pool does not support worker resource cleanup");
if (!this.#registeredHosts.has(systemProcessOwnershipHost)) {
this.#registeredHosts.add(systemProcessOwnershipHost);
this.onCleanupWorkerContext(() => systemProcessOwnershipHost.close?.());
}
if (!this.#registeredStubOwners.has(closeShellStubDispatcher)) {
this.#registeredStubOwners.add(closeShellStubDispatcher);
this.onCleanupWorkerContext(closeShellStubDispatcher);
}
}
}