Skip to content

Commit 46a556b

Browse files
committed
add safe wrapper around stop
1 parent 10537e1 commit 46a556b

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

packages/core/src/shared/utilities/processUtils.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,10 @@ export class ChildProcessTracker {
8585
}
8686

8787
private cleanUp() {
88-
console.log('in clean up')
8988
const terminatedProcesses = Array.from(this.#pids.values()).filter(
9089
(pid: number) => this.#processByPid.get(pid)?.stopped
9190
)
9291
for (const pid of terminatedProcesses) {
93-
console.log('removing %s', pid)
9492
this.delete(pid)
9593
}
9694
}
@@ -173,6 +171,7 @@ export class ChildProcessTracker {
173171
*/
174172
export class ChildProcess {
175173
static #runningProcesses = new ChildProcessTracker()
174+
static stopTimeout = 3000
176175
#childProcess: proc.ChildProcess | undefined
177176
#processErrors: Error[] = []
178177
#processResult: ChildProcessResult | undefined
@@ -389,7 +388,7 @@ export class ChildProcess {
389388
child.kill(signal)
390389

391390
if (force === true) {
392-
waitUntil(async () => this.stopped, { timeout: 3000, interval: 200, truthy: true })
391+
waitUntil(async () => this.stopped, { timeout: ChildProcess.stopTimeout, interval: 200, truthy: true })
393392
.then((stopped) => {
394393
if (!stopped) {
395394
child.kill('SIGKILL')

packages/core/src/test/shared/utilities/processUtils.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,11 @@ function getSleepCmd() {
360360
return isWin() ? 'timeout' : 'sleep'
361361
}
362362

363+
async function stopAndWait(cp: ChildProcess) {
364+
cp.stop(true)
365+
await waitUntil(async () => cp.stopped, { timeout: ChildProcess.stopTimeout * 2, interval: 100, truthy: true })
366+
}
367+
363368
describe('ChildProcessTracker', function () {
364369
let tracker: ChildProcessTracker
365370
let clock: FakeTimers.InstalledClock
@@ -389,7 +394,7 @@ describe('ChildProcessTracker', function () {
389394

390395
await clock.tickAsync(ChildProcessTracker.pollingInterval)
391396
assert.strictEqual(tracker.has(childProcess), true, 'process was mistakenly removed')
392-
childProcess.stop(true)
397+
await stopAndWait(childProcess)
393398

394399
await clock.tickAsync(ChildProcessTracker.pollingInterval)
395400
assert.strictEqual(tracker.has(childProcess), false, 'process was not removed after stopping')
@@ -406,8 +411,7 @@ describe('ChildProcessTracker', function () {
406411
assert.strictEqual(tracker.has(childProcess1), true, 'Missing first process')
407412
assert.strictEqual(tracker.has(childProcess2), true, 'Missing second process')
408413

409-
childProcess1.stop()
410-
console.log('child process 1 stopped')
414+
await stopAndWait(childProcess1)
411415
await clock.tickAsync(ChildProcessTracker.pollingInterval)
412416
assert.strictEqual(tracker.has(childProcess2), true, 'second process was mistakenly removed')
413417
assert.strictEqual(tracker.has(childProcess1), false, 'first process was not removed after stopping it')

0 commit comments

Comments
 (0)