mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-20 16:53:12 -07:00
test: fix hanging worker in InteractiveRun
This commit is contained in:
@@ -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> {
|
||||
|
||||
Reference in New Issue
Block a user