Skip to content

Commit 045f9f0

Browse files
committed
fix failing tests
1 parent bf515e0 commit 045f9f0

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,6 @@ export class ChildProcessTracker {
111111
}
112112

113113
private async checkProcessUsage(pid: number): Promise<void> {
114-
const doesExceedThreshold = (resource: keyof ProcessStats, value: number) => {
115-
const threshold = ChildProcessTracker.thresholds[resource]
116-
return value > threshold
117-
}
118114
const warn = (resource: SystemResource, value: number) => {
119115
telemetry.ide_childProcessWarning.run((span) => {
120116
this.logger.warn(`Process ${this.getProcessAsStr(pid)} exceeded ${resource} threshold: ${value}`)
@@ -136,6 +132,11 @@ export class ChildProcessTracker {
136132
warn(toTelemetryResource(processStat), stats[processStat])
137133
}
138134
}
135+
136+
function doesExceedThreshold(resource: keyof ProcessStats, value: number) {
137+
const threshold = ChildProcessTracker.thresholds[resource]
138+
return value > threshold
139+
}
139140
}
140141

141142
public getProcessAsStr(pid: pid): string {

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ describe('ChildProcessTracker', function () {
464464
memoryBytes: 0,
465465
}
466466

467-
usageMock.resolves(highCpu)
467+
usageMock.returns(highCpu)
468468

469469
await clock.tickAsync(ChildProcessTracker.pollingInterval)
470470
assertLogsContain('exceeded cpu threshold', false, 'warn')
@@ -483,7 +483,7 @@ describe('ChildProcessTracker', function () {
483483
memoryBytes: ChildProcessTracker.thresholds.memoryBytes + 1,
484484
}
485485

486-
usageMock.resolves(highMemory)
486+
usageMock.returns(highMemory)
487487
await clock.tickAsync(ChildProcessTracker.pollingInterval)
488488
assertLogsContain('exceeded memory threshold', false, 'warn')
489489
assertTelemetry('ide_childProcessWarning', {
@@ -497,9 +497,9 @@ describe('ChildProcessTracker', function () {
497497
it('includes pid in logs', async function () {
498498
const runningProcess = startSleepProcess()
499499

500-
usageMock.resolves({
501-
cpu: ChildProcessTracker.thresholds.cpuPercent + 1,
502-
memory: 0,
500+
usageMock.returns({
501+
cpuPercent: 0,
502+
memoryBytes: ChildProcessTracker.thresholds.memoryBytes + 1,
503503
})
504504

505505
await clock.tickAsync(ChildProcessTracker.pollingInterval)
@@ -511,7 +511,7 @@ describe('ChildProcessTracker', function () {
511511
it('does not log for processes within threshold', async function () {
512512
const runningProcess = startSleepProcess()
513513

514-
usageMock.resolves({
514+
usageMock.returns({
515515
cpu: ChildProcessTracker.thresholds.cpuPercent - 1,
516516
memory: ChildProcessTracker.thresholds.memoryBytes - 1,
517517
})

0 commit comments

Comments
 (0)