@@ -360,9 +360,10 @@ function getSleepCmd() {
360360 return isWin ( ) ? 'timeout' : 'sleep'
361361}
362362
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 ) {
364365 cp . stop ( true )
365- await waitUntil ( async ( ) => cp . stopped , { timeout : ChildProcess . stopTimeout * 2 , interval : 100 , truthy : true } )
366+ await clock . tickAsync ( ChildProcess . stopTimeout )
366367}
367368
368369describe ( 'ChildProcessTracker' , function ( ) {
@@ -394,12 +395,12 @@ describe('ChildProcessTracker', function () {
394395
395396 await clock . tickAsync ( ChildProcessTracker . pollingInterval )
396397 assert . strictEqual ( tracker . has ( childProcess ) , true , 'process was mistakenly removed' )
397- await stopAndWait ( childProcess )
398+ await stopAndWait ( childProcess , clock )
398399
399400 await clock . tickAsync ( ChildProcessTracker . pollingInterval )
400401 assert . strictEqual ( tracker . has ( childProcess ) , false , 'process was not removed after stopping' )
401402 } )
402- for ( const _ of Array . from ( { length : 1000 } ) ) {
403+ for ( const _ of Array . from ( { length : 100 } ) ) {
403404 it ( 'multiple processes from same command are tracked seperately' , async function ( ) {
404405 const childProcess1 = new ChildProcess ( getSleepCmd ( ) , [ '90' ] )
405406 const childProcess2 = new ChildProcess ( getSleepCmd ( ) , [ '90' ] )
@@ -411,7 +412,7 @@ describe('ChildProcessTracker', function () {
411412 assert . strictEqual ( tracker . has ( childProcess1 ) , true , 'Missing first process' )
412413 assert . strictEqual ( tracker . has ( childProcess2 ) , true , 'Missing second process' )
413414
414- await stopAndWait ( childProcess1 )
415+ await stopAndWait ( childProcess1 , clock )
415416 await clock . tickAsync ( ChildProcessTracker . pollingInterval )
416417 assert . strictEqual ( tracker . has ( childProcess2 ) , true , 'second process was mistakenly removed' )
417418 assert . strictEqual ( tracker . has ( childProcess1 ) , false , 'first process was not removed after stopping it' )
0 commit comments