Skip to content

Commit fd91f2a

Browse files
committed
fix: adjust tests
1 parent 9003bde commit fd91f2a

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

packages/core/src/shared/telemetry/util.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ function validateMetadata(metricName: string, metadata: MetadataObj, fatal: bool
346346

347347
// TODO: there are many instances in the toolkit where we emit metrics with missing fields. If those can be removed, we can configure this to throw in CI.
348348
if (metadata.missingFields) {
349-
logWarningOnce(`"${metricName}" emitted with missing fields: ${metadata.missingFields}`)
349+
const logMsg = `${msgPrefix} "${metricName}" emitted with missing fields: ${metadata.missingFields}`
350+
logWarningOnce(logMsg)
350351
}
351352
}
352353

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import * as crossSpawn from 'cross-spawn'
88
import * as logger from '../logger/logger'
99
import { Timeout, CancellationError, waitUntil } from './timeoutUtils'
1010
import { PollingSet } from './pollingSet'
11-
import { CircularBuffer } from './collectionUtils'
1211
import { oncePerUniqueArg } from './functionUtils'
1312

1413
export interface RunParameterContext {
@@ -82,7 +81,6 @@ export interface ProcessStats {
8281
export class ChildProcessTracker {
8382
static readonly pollingInterval: number = 10000 // Check usage every 10 seconds
8483
static readonly logger = logger.getLogger('childProcess')
85-
static readonly loggedPids = new CircularBuffer(1000)
8684
#processByPid: Map<number, ChildProcess> = new Map<number, ChildProcess>()
8785
#pids: PollingSet<number>
8886

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,6 @@ describe('ChildProcessTracker', function () {
395395
usageMock = sinon.stub(ChildProcessTracker.prototype, 'getUsage')
396396
})
397397

398-
beforeEach(function () {
399-
ChildProcessTracker.loggedPids.clear()
400-
})
401-
402398
afterEach(function () {
403399
tracker.clear()
404400
usageMock.reset()
@@ -451,26 +447,33 @@ describe('ChildProcessTracker', function () {
451447
assert.strictEqual(tracker.size, 0, 'expected tracker to be empty')
452448
})
453449

454-
it('logs a warning message when system usage exceeds threshold', async function () {
450+
it('logs a warning message when cpu usage exceeds threshold', async function () {
455451
const runningProcess = startSleepProcess()
456452
tracker.add(runningProcess.childProcess)
457453

458454
const highCpu: ProcessStats = {
459455
cpu: defaultProcessWarnThresholds.cpu + 1,
460456
memory: 0,
461457
}
462-
const highMemory: ProcessStats = {
463-
cpu: 0,
464-
memory: defaultProcessWarnThresholds.memory + 1,
465-
}
466458

467459
usageMock.returns(highCpu)
468460

469461
await clock.tickAsync(ChildProcessTracker.pollingInterval)
470462
assertLogsContain('exceeded cpu threshold', false, 'warn')
471463

472-
ChildProcessTracker.loggedPids.clear()
464+
await stopAndWait(runningProcess)
465+
})
466+
467+
it('logs a warning message when memory usage exceeds threshold', async function () {
468+
const runningProcess = startSleepProcess()
469+
tracker.add(runningProcess.childProcess)
470+
471+
const highMemory: ProcessStats = {
472+
cpu: 0,
473+
memory: defaultProcessWarnThresholds.memory + 1,
474+
}
473475
usageMock.returns(highMemory)
476+
474477
await clock.tickAsync(ChildProcessTracker.pollingInterval)
475478
assertLogsContain('exceeded memory threshold', false, 'warn')
476479

0 commit comments

Comments
 (0)