test: fix hanging worker in InteractiveRun

This commit is contained in:
mkorwel
2026-04-21 00:06:11 +00:00
parent cc61d0a7f9
commit 13fc9c6d76
+21 -1
View File
@@ -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<void>((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<number> {