mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-19 23:05:21 +00:00
test(terminal): wait for a killed worker's processes before cleanup (#10198)
Four worker-terminal-manager tests SIGKILL a terminal worker whose terminal program runs in the test's temporary home. On Windows that program ends only when the dead worker's console closes, a moment later. afterEach then removed the home with a 0.5 s retry budget, and Windows refuses to remove a directory that is a live process's working directory, so cleanup failed with EBUSY. The tests now kill a worker through crashWorker, which records the worker and its terminal programs. afterEach waits up to 10 s for them to end before it removes the temporary dirs. Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
68cfad2c8a
commit
b76533830a
@@ -217,6 +217,16 @@ function trackTerminal(session: TerminalSession): TerminalSession {
|
||||
return session;
|
||||
}
|
||||
|
||||
// Processes of workers a test killed. On Windows a killed worker's terminal programs end only
|
||||
// once its console closes, a moment later, and a temporary dir that is still a live program's
|
||||
// cwd cannot be removed. afterEach waits for them before it removes the dirs.
|
||||
const crashedWorkerProcesses: number[] = [];
|
||||
|
||||
function crashWorker(record: TerminalWorkerRecord): void {
|
||||
crashedWorkerProcesses.push(record.pid, ...record.terminals.map((terminal) => terminal.pid));
|
||||
process.kill(record.pid, "SIGKILL");
|
||||
}
|
||||
|
||||
async function removeTemporaryDir(dir: string): Promise<void> {
|
||||
let lastError: unknown;
|
||||
for (let attempt = 0; attempt < 5; attempt += 1) {
|
||||
@@ -245,6 +255,8 @@ afterEach(async () => {
|
||||
);
|
||||
await manager?.closeTerminals();
|
||||
manager = null;
|
||||
const crashed = crashedWorkerProcesses.splice(0);
|
||||
await waitForCondition(() => !crashed.some(isProcessAlive), 10000);
|
||||
while (temporaryDirs.length > 0) {
|
||||
const dir = temporaryDirs.pop();
|
||||
if (dir) {
|
||||
@@ -273,7 +285,7 @@ it("retires a killed worker's sessions and shares one replacement across concurr
|
||||
);
|
||||
const exits: unknown[] = [];
|
||||
terminal.onExit((info) => exits.push(info));
|
||||
process.kill(file.record.pid, "SIGKILL");
|
||||
crashWorker(file.record);
|
||||
await waitForCondition(() => manager!.getTerminal(terminal.id) === undefined, 10000);
|
||||
expect(changes).toContainEqual([]);
|
||||
expect(exits).toHaveLength(1);
|
||||
@@ -355,7 +367,7 @@ it.each(["detach", "closeTerminals"] as const)(
|
||||
...nodeTerminalCommand("setInterval(() => {}, 1000)"),
|
||||
});
|
||||
const [record] = await workerRecords(paseoHome);
|
||||
process.kill(record!.pid, "SIGKILL");
|
||||
crashWorker(record!);
|
||||
await manager[operation]();
|
||||
await expect(
|
||||
manager.createTerminal({ workspaceId: "ws-stop-recovery", cwd: paseoHome }),
|
||||
@@ -377,7 +389,7 @@ it.each(["detach", "closeTerminals"] as const)(
|
||||
...nodeTerminalCommand("setInterval(() => {}, 1000)"),
|
||||
});
|
||||
const [record] = await workerRecords(paseoHome);
|
||||
process.kill(record!.pid, "SIGKILL");
|
||||
crashWorker(record!);
|
||||
await waitForCondition(() => !manager!.getTerminal(terminal.id), 10000);
|
||||
const creating = manager.createTerminal({ workspaceId: "ws-launch-race", cwd: paseoHome });
|
||||
const rejected = expect(creating).rejects.toBeInstanceOf(NoTerminalWorkerAvailableError);
|
||||
@@ -416,7 +428,7 @@ it.each(["current", "draining"] as const)(
|
||||
const healthyId = target === "current" ? drainingId : added.id;
|
||||
const healthy = manager.getTerminal(healthyId);
|
||||
expect(healthy).toBeDefined();
|
||||
process.kill(target === "current" ? current.pid : draining.pid, "SIGKILL");
|
||||
crashWorker(target === "current" ? current : draining);
|
||||
await waitForCondition(() => !manager!.getTerminal(deadId), 10000);
|
||||
expect(manager.getTerminal(healthyId)).toBe(healthy);
|
||||
expect(await readReplay(manager, healthyId)).not.toBeNull();
|
||||
|
||||
Reference in New Issue
Block a user