@@ -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+
363368describe ( '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