Skip to content

Commit 57de940

Browse files
committed
wip
1 parent 2080abd commit 57de940

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

tests/e2e/utils/process.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { spawn, SpawnOptions } from 'node:child_process';
22
import * as child_process from 'node:child_process';
33
import { getGlobalVariable, getGlobalVariablesEnv } from './env';
4-
import { setTimeout as sleep } from 'node:timers/promises';
54
import { delimiter, join, resolve } from 'node:path';
65
import { stripVTControlCharacters, styleText } from 'node:util';
76

@@ -255,35 +254,33 @@ export async function waitForAnyProcessOutputToMatch(
255254
return matchingProcess;
256255
}
257256

257+
async function killProcess(pid: number, signal: string): Promise<void> {
258+
if (process.platform === 'win32') {
259+
// /T kills child processes, /F forces it
260+
await exec(`taskkill /pid ${pid} /T /F`);
261+
} else {
262+
process.kill(-pid, signal);
263+
}
264+
}
265+
258266
/**
259-
* Kills all tracked processes with a retry mechanism.
267+
* Kills all tracked processes
260268
*/
261269
export async function killAllProcesses(signal: NodeJS.Signals = 'SIGTERM'): Promise<void> {
262270
let attempts = 0;
263-
const maxRetries = 3;
264-
265-
while (_processes.length > 0 && attempts < maxRetries) {
271+
while (_processes.length > 0) {
266272
attempts++;
267273

268274
// Iterate backwards so we can remove elements while looping if needed.
269275
for (let i = _processes.length - 1; i >= 0; i--) {
270276
const childProc = _processes[i];
271277

272-
if (!childProc || childProc.killed) {
278+
if (!childProc || childProc.killed || !childProc.pid) {
273279
_processes.splice(i, 1);
274280
continue;
275281
}
276282

277-
const killed = childProc.kill(signal);
278-
if (killed) {
279-
_processes.splice(i, 1);
280-
continue;
281-
}
282-
}
283-
284-
// If still have processes, wait a bit before the next retry (e.g., 100ms)
285-
if (_processes.length > 0 && attempts < maxRetries) {
286-
await sleep(100);
283+
await killProcess(childProc.pid, signal);
287284
}
288285
}
289286
}

0 commit comments

Comments
 (0)