From 13fc9c6d767f51cb3720e6bdfc216adff5f3e97a Mon Sep 17 00:00:00 2001 From: mkorwel Date: Tue, 21 Apr 2026 00:06:11 +0000 Subject: [PATCH] test: fix hanging worker in InteractiveRun --- packages/test-utils/src/test-rig.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/test-utils/src/test-rig.ts b/packages/test-utils/src/test-rig.ts index 734c1b9546..af387cf86a 100644 --- a/packages/test-utils/src/test-rig.ts +++ b/packages/test-utils/src/test-rig.ts @@ -224,6 +224,7 @@ export interface ParsedLog { export class InteractiveRun { ptyProcess: pty.IPty; public output = ''; + private _isDead = false; constructor(ptyProcess: pty.IPty) { this.ptyProcess = ptyProcess; @@ -233,6 +234,9 @@ export class InteractiveRun { process.stdout.write(data); } }); + ptyProcess.onExit(() => { + this._isDead = true; + }); } async expectText(text: string, timeout?: number) { @@ -295,7 +299,23 @@ export class InteractiveRun { } async kill() { - this.ptyProcess.kill(); + if (this._isDead) return; + return new Promise((resolve) => { + const timer = setTimeout(() => { + try { + process.kill(this.ptyProcess.pid, 'SIGKILL'); + } catch (e) { + // Ignore if already dead + } + resolve(); // Resolve anyway to avoid hanging tests! + }, 5000); // Wait 5 seconds + + this.ptyProcess.onExit(() => { + clearTimeout(timer); + resolve(); + }); + this.ptyProcess.kill(); + }); } expectExit(): Promise {