@@ -360,9 +360,10 @@ function getSleepCmd() {
360
360
return isWin ( ) ? 'timeout' : 'sleep'
361
361
}
362
362
363
- async function stopAndWait ( cp : ChildProcess ) {
363
+ // ChildProcess.stop is non-async and doesn't wait for the process to be stopped.
364
+ async function stopAndWait ( cp : ChildProcess , clock : FakeTimers . InstalledClock ) {
364
365
cp . stop ( true )
365
- await waitUntil ( async ( ) => cp . stopped , { timeout : ChildProcess . stopTimeout * 2 , interval : 100 , truthy : true } )
366
+ await clock . tickAsync ( ChildProcess . stopTimeout )
366
367
}
367
368
368
369
describe ( 'ChildProcessTracker' , function ( ) {
@@ -394,12 +395,12 @@ describe('ChildProcessTracker', function () {
394
395
395
396
await clock . tickAsync ( ChildProcessTracker . pollingInterval )
396
397
assert . strictEqual ( tracker . has ( childProcess ) , true , 'process was mistakenly removed' )
397
- await stopAndWait ( childProcess )
398
+ await stopAndWait ( childProcess , clock )
398
399
399
400
await clock . tickAsync ( ChildProcessTracker . pollingInterval )
400
401
assert . strictEqual ( tracker . has ( childProcess ) , false , 'process was not removed after stopping' )
401
402
} )
402
- for ( const _ of Array . from ( { length : 1000 } ) ) {
403
+ for ( const _ of Array . from ( { length : 100 } ) ) {
403
404
it ( 'multiple processes from same command are tracked seperately' , async function ( ) {
404
405
const childProcess1 = new ChildProcess ( getSleepCmd ( ) , [ '90' ] )
405
406
const childProcess2 = new ChildProcess ( getSleepCmd ( ) , [ '90' ] )
@@ -411,7 +412,7 @@ describe('ChildProcessTracker', function () {
411
412
assert . strictEqual ( tracker . has ( childProcess1 ) , true , 'Missing first process' )
412
413
assert . strictEqual ( tracker . has ( childProcess2 ) , true , 'Missing second process' )
413
414
414
- await stopAndWait ( childProcess1 )
415
+ await stopAndWait ( childProcess1 , clock )
415
416
await clock . tickAsync ( ChildProcessTracker . pollingInterval )
416
417
assert . strictEqual ( tracker . has ( childProcess2 ) , true , 'second process was mistakenly removed' )
417
418
assert . strictEqual ( tracker . has ( childProcess1 ) , false , 'first process was not removed after stopping it' )
0 commit comments