mirror of
https://github.com/getpaseo/paseo.git
synced 2026-12-04 06:06:26 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
acde63e614 |
@@ -26,7 +26,7 @@ import {
|
||||
rmSync,
|
||||
writeFileSync,
|
||||
} from "node:fs";
|
||||
import { delimiter, join } from "node:path";
|
||||
import { basename, delimiter, join } from "node:path";
|
||||
import { tmpdir } from "node:os";
|
||||
import pino from "pino";
|
||||
import {
|
||||
@@ -1667,25 +1667,53 @@ async function startManagerWithWorkerProtocol(
|
||||
}
|
||||
}
|
||||
|
||||
// Whether the program still accepts connections on its socket. Unlike its pid, which Windows
|
||||
// hands to another process as soon as the program ends and records without a birth time, the
|
||||
// socket closes with the program and nothing else answers on it.
|
||||
async function programListens(socketPath: string): Promise<boolean> {
|
||||
return await new Promise((resolve) => {
|
||||
const socket = createConnection(socketPath);
|
||||
socket.once("connect", () => {
|
||||
socket.destroy();
|
||||
resolve(true);
|
||||
});
|
||||
socket.once("error", () => resolve(false));
|
||||
});
|
||||
}
|
||||
|
||||
// A terminal running an idle program in a worker that reports `protocolVersion`, left running
|
||||
// after its daemon lets go (stop --keep-terminals).
|
||||
// after its daemon lets go (stop --keep-terminals). The program listens on `programSocket`.
|
||||
async function leaveWorkerWithTerminal(
|
||||
paseoHome: string,
|
||||
protocolVersion: number,
|
||||
): Promise<{ terminalId: string; programPid: number; workerPid: number; cwd: string }> {
|
||||
): Promise<{
|
||||
terminalId: string;
|
||||
programPid: number;
|
||||
programSocket: string;
|
||||
workerPid: number;
|
||||
cwd: string;
|
||||
}> {
|
||||
const cwd = mkdtempSync(join(tmpdir(), "worker-terminal-manager-protocol-"));
|
||||
temporaryDirs.push(cwd);
|
||||
const programSocket =
|
||||
process.platform === "win32"
|
||||
? `\\\\.\\pipe\\paseo-test-program-${basename(cwd)}`
|
||||
: join(cwd, "program.sock");
|
||||
const previous = await startManagerWithWorkerProtocol(paseoHome, protocolVersion);
|
||||
const session = await previous.createTerminal({
|
||||
workspaceId: "ws-protocol",
|
||||
cwd,
|
||||
...nodeTerminalCommand("setInterval(() => {}, 1000);"),
|
||||
...nodeTerminalCommand(
|
||||
`require("node:net").createServer().listen(${JSON.stringify(programSocket)}); setInterval(() => {}, 1000);`,
|
||||
),
|
||||
});
|
||||
await waitForCondition(() => programListens(programSocket), 10000);
|
||||
const [record] = await workerRecords(paseoHome);
|
||||
await previous.detach();
|
||||
return {
|
||||
terminalId: session.id,
|
||||
programPid: (await recordedTerminalPids(paseoHome)).get(session.id)!,
|
||||
programSocket,
|
||||
workerPid: record!.pid,
|
||||
cwd,
|
||||
};
|
||||
@@ -1697,24 +1725,14 @@ it.each([1, 4, 5])(
|
||||
const paseoHome = createTemporaryHome();
|
||||
const old = await leaveWorkerWithTerminal(paseoHome, version);
|
||||
const [record] = await workerRecords(paseoHome);
|
||||
const program = record!.terminals.find((entry) => entry.id === old.terminalId)!;
|
||||
const inspector = createTerminalWorkerProcessInspector();
|
||||
|
||||
manager = await startRealWorkerManager({ paseoHome });
|
||||
|
||||
expect(await readUnconfirmedTerminalCleanup(paseoHome)).toEqual([]);
|
||||
// Startup launches a replacement worker after cleanup. Either old PID may already
|
||||
// belong to another process, so verify that the recorded birth identities are gone.
|
||||
// Startup launches a replacement worker after cleanup. The program's PID may already
|
||||
// belong to another process, so its own socket is what proves it gone.
|
||||
await waitForCondition(() => !isProcessAlive(record!.pid), 10000);
|
||||
await expect
|
||||
.poll(
|
||||
async () =>
|
||||
!isProcessAlive(program.pid) ||
|
||||
classifyTerminalProgramProcess(program, await inspector.inspect(program.pid)).status ===
|
||||
"unrelated",
|
||||
{ timeout: 10000 },
|
||||
)
|
||||
.toBe(true);
|
||||
await expect.poll(() => programListens(old.programSocket), { timeout: 10000 }).toBe(false);
|
||||
expect(manager.getTerminal(old.terminalId)).toBeUndefined();
|
||||
const workers = await workerRecords(paseoHome);
|
||||
expect(workers).toHaveLength(1);
|
||||
|
||||
Reference in New Issue
Block a user