Skip to content

Commit 10db36d

Browse files
committed
test(restart): exercise stale identities and refused endpoints
1 parent 87b39d5 commit 10db36d

3 files changed

Lines changed: 19 additions & 8 deletions

File tree

‎structure/ops/test-sandbox-cleanup.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,6 @@ failure retains the home. A controlled foreign process injected at a stale journ
147147
`tests/fixtures/restart-parent-ownership-runner.ts` journals process phases and captures the
148148
fence probe's output continuously. Failure assertions include that evidence and the replacement
149149
handoff log, including when the parent is terminated before its probe returns.
150-
The fixture bundles its unchanged product graph once into the recognized source-launch entry
151-
before spawning. The handoff watchdog and outer test budget retain their original limits;
152-
repeated cold module resolution/transpilation is setup, rather than handoff work.
150+
The fixture bundles the product graph once into the recognized source-launch entry before
151+
spawning. Cold module resolution and transpilation count as setup, not handoff work. The
152+
18-second handoff watchdog starts after spawn; bundling counts against the outer test budget.

‎tests/fixtures/restart-parent-ownership-runner.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,17 @@ async function recover(): Promise<void> {
4949

5050
if (probe) {
5151
const before = readPidFileValue();
52+
const runtime = readRuntimePort()!;
53+
const observed = await observeProxyLiveness();
54+
const endpointsRefused = await Promise.all(["127.0.0.1", "[::1]"].map(async host => {
55+
try { await fetch(`http://${host}:${runtime.port}/healthz`, { signal: AbortSignal.timeout(1_000) }); return false; }
56+
catch (error) { return ["ECONNREFUSED", "ConnectionRefused"].includes((error as NodeJS.ErrnoException).code ?? ""); }
57+
}));
5258
let refused = false;
5359
try { await recover(); }
5460
catch (error) { refused = (error as Error).message.includes("ownership is unverified"); }
55-
console.log(JSON.stringify({ refused, pidUnchanged: before === readPidFileValue() }));
61+
console.log(JSON.stringify({ refused, pidUnchanged: before === readPidFileValue(),
62+
observed: observed.kind, endpointsRefused }));
5663
process.exit(refused ? 0 : 2);
5764
}
5865

‎tests/server/system-restart-ownership.test.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ import { isProcessAlive } from "../../src/lib/process-control";
1515
let home: TempHome | undefined;
1616
let settleProcesses: (() => Promise<void>) | undefined;
1717
afterEach(async () => {
18-
await settleProcesses?.();
18+
const settle = settleProcesses, owned = home;
1919
settleProcesses = undefined;
20-
home?.remove(); home = undefined;
20+
home = undefined;
21+
await settle?.();
22+
owned?.remove();
2123
});
2224
function fixture(): TempHome { return home = createTempHome("ocx-restart-parent-ownership-"); }
2325

@@ -170,7 +172,7 @@ await import(${JSON.stringify(fixturePath("restart-parent-ownership-runner.ts"))
170172
expect(result).toMatchObject({ parentPid: parent.pid, parentAliveBeforeRecovery: true,
171173
observed: "absent", parentExited: true });
172174
expect(result.parentResult).toMatchObject({ code: 0, pid: parent.pid,
173-
beforeHandoff: { refused: true, pidUnchanged: true },
175+
beforeHandoff: { refused: true, pidUnchanged: true, observed: "unknown", endpointsRefused: [true, true] },
174176
successorPid: result.pid, successorRuntime: { pid: result.pid, port: result.port } });
175177
expect(readFileSync(owned.path("restart-handoff.log"), "utf8")).toContain("is serving port");
176178
} catch (error) {
@@ -187,7 +189,9 @@ await import(${JSON.stringify(fixturePath("restart-parent-ownership-runner.ts"))
187189
stdout: "ignore", stderr: "ignore",
188190
});
189191
try {
190-
appendFileSync(pidsPath, foreign.pid + "\n");
192+
appendFileSync(pidsPath, (process.platform === "win32"
193+
? String(foreign.pid)
194+
: JSON.stringify({ pid: foreign.pid, start: "stale-journal-identity" })) + "\n");
191195
await settleProcesses();
192196
expect(isProcessAlive(foreign.pid)).toBe(true);
193197
} finally {

0 commit comments

Comments
 (0)