Skip to content

Commit b3d1fd4

Browse files
committed
add testing
1 parent 6385594 commit b3d1fd4

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export class ChildProcessTracker {
162162

163163
public async logAllUsage(): Promise<void> {
164164
if (this.size === 0) {
165-
this.logger.info('No active subprocesses')
165+
this.logger.info('No Active Subprocesses')
166166
return
167167
}
168168
const usage = await this.getAllUsage()

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ describe('ChildProcessTracker', function () {
400400

401401
after(function () {
402402
clock.uninstall()
403+
usageMock.restore()
403404
})
404405

405406
it(`removes stopped processes every ${ChildProcessTracker.pollingInterval / 1000} seconds`, async function () {
@@ -500,3 +501,38 @@ describe('ChildProcessTracker', function () {
500501
await stopAndWait(runningProcess)
501502
})
502503
})
504+
505+
describe('ChildProcessTracker.logAllUsage', function () {
506+
let tracker: ChildProcessTracker
507+
508+
before(function () {
509+
tracker = ChildProcessTracker.instance
510+
})
511+
512+
afterEach(function () {
513+
tracker.clear()
514+
})
515+
516+
it('logAllUsage includes only active processes', async function () {
517+
const runningProcess1 = startSleepProcess()
518+
const runningProcess2 = startSleepProcess()
519+
520+
tracker.add(runningProcess1.childProcess)
521+
tracker.add(runningProcess2.childProcess)
522+
523+
assert.ok(tracker.has(runningProcess1.childProcess), 'Missing first process')
524+
assert.ok(tracker.has(runningProcess2.childProcess), 'Missing seconds process')
525+
526+
await stopAndWait(runningProcess1)
527+
528+
await tracker.logAllUsage()
529+
530+
assert.throws(() => assertLogsContain(runningProcess1.childProcess.pid().toString(), false, 'info'))
531+
assertLogsContain(runningProcess2.childProcess.pid().toString(), false, 'info')
532+
})
533+
534+
it('logAllUsage defaults to empty message when empty', async function () {
535+
await tracker.logAllUsage()
536+
assertLogsContain('No Active Subprocesses', false, 'info')
537+
})
538+
})

0 commit comments

Comments
 (0)