Skip to content

Commit 5c652b6

Browse files
committed
add more tests
1 parent 72681fd commit 5c652b6

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

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

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,17 @@ function getSleepCmd() {
363363
describe('ChildProcessTracker', function () {
364364
let tracker: ChildProcessTracker
365365
let clock: FakeTimers.InstalledClock
366+
let usageMock: sinon.SinonStub
367+
366368
before(function () {
367369
clock = installFakeClock()
368370
tracker = new ChildProcessTracker()
371+
usageMock = sinon.stub(ChildProcessTracker.prototype, 'getUsage')
369372
})
370373

371374
afterEach(function () {
372375
tracker.clear()
376+
usageMock.reset()
373377
})
374378

375379
after(function () {
@@ -413,7 +417,6 @@ describe('ChildProcessTracker', function () {
413417
childProcess.run().catch(() => assert.fail('sleep command threw an error'))
414418
tracker.add(childProcess)
415419

416-
const usageMock = sinon.stub(ChildProcessTracker.prototype, 'getUsage')
417420
const highCpu: ProcessStats = {
418421
cpu: ChildProcessTracker.thresholds.cpu + 1,
419422
memory: 0,
@@ -443,7 +446,35 @@ describe('ChildProcessTracker', function () {
443446
usageMock.resolves(highTime)
444447
await clock.tickAsync(ChildProcessTracker.pollingInterval)
445448
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)
446477

447-
sinon.restore()
478+
assert.throws(() => assertLogsContain(childProcess.pid().toString(), false, 'warn'))
448479
})
449480
})

0 commit comments

Comments
 (0)