@@ -363,13 +363,17 @@ function getSleepCmd() {
363
363
describe ( 'ChildProcessTracker' , function ( ) {
364
364
let tracker : ChildProcessTracker
365
365
let clock : FakeTimers . InstalledClock
366
+ let usageMock : sinon . SinonStub
367
+
366
368
before ( function ( ) {
367
369
clock = installFakeClock ( )
368
370
tracker = new ChildProcessTracker ( )
371
+ usageMock = sinon . stub ( ChildProcessTracker . prototype , 'getUsage' )
369
372
} )
370
373
371
374
afterEach ( function ( ) {
372
375
tracker . clear ( )
376
+ usageMock . reset ( )
373
377
} )
374
378
375
379
after ( function ( ) {
@@ -413,7 +417,6 @@ describe('ChildProcessTracker', function () {
413
417
childProcess . run ( ) . catch ( ( ) => assert . fail ( 'sleep command threw an error' ) )
414
418
tracker . add ( childProcess )
415
419
416
- const usageMock = sinon . stub ( ChildProcessTracker . prototype , 'getUsage' )
417
420
const highCpu : ProcessStats = {
418
421
cpu : ChildProcessTracker . thresholds . cpu + 1 ,
419
422
memory : 0 ,
@@ -443,7 +446,35 @@ describe('ChildProcessTracker', function () {
443
446
usageMock . resolves ( highTime )
444
447
await clock . tickAsync ( ChildProcessTracker . pollingInterval )
445
448
assertLogsContain ( 'exceeded time threshold' , false , 'warn' )
449
+ } )
450
+
451
+ it ( 'includes pid in logs' , async function ( ) {
452
+ const childProcess = new ChildProcess ( getSleepCmd ( ) , [ '90' ] )
453
+ childProcess . run ( ) . catch ( ( ) => assert . fail ( 'sleep command threw an error' ) )
454
+ tracker . add ( childProcess )
455
+
456
+ usageMock . resolves ( {
457
+ cpu : ChildProcessTracker . thresholds . cpu + 1 ,
458
+ memory : 0 ,
459
+ elapsed : 0 ,
460
+ } )
461
+
462
+ await clock . tickAsync ( ChildProcessTracker . pollingInterval )
463
+ assertLogsContain ( childProcess . pid ( ) . toString ( ) , false , 'warn' )
464
+ } )
465
+
466
+ it ( 'does not log for processes within threshold' , async function ( ) {
467
+ const childProcess = new ChildProcess ( getSleepCmd ( ) , [ '90' ] )
468
+ childProcess . run ( ) . catch ( ( ) => assert . fail ( 'sleep command threw an error' ) )
469
+
470
+ usageMock . resolves ( {
471
+ cpu : ChildProcessTracker . thresholds . cpu - 1 ,
472
+ memory : ChildProcessTracker . thresholds . memory - 1 ,
473
+ elapsed : ChildProcessTracker . thresholds . elapsed - 1 ,
474
+ } )
475
+
476
+ await clock . tickAsync ( ChildProcessTracker . pollingInterval )
446
477
447
- sinon . restore ( )
478
+ assert . throws ( ( ) => assertLogsContain ( childProcess . pid ( ) . toString ( ) , false , 'warn' ) )
448
479
} )
449
480
} )
0 commit comments