Skip to content

Commit efe336e

Browse files
committed
improve test performance by properly stopping timer
1 parent 2df7506 commit efe336e

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class PollingSet<T> extends Set<T> {
5151
}
5252

5353
public override clear(): void {
54-
this.pollTimer = undefined
54+
this.clearTimer()
5555
super.clear()
5656
}
5757
}

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -394,23 +394,24 @@ describe('ChildProcessTracker', function () {
394394
await clock.tickAsync(ChildProcessTracker.pollingInterval)
395395
assert.strictEqual(tracker.has(childProcess), false, 'process was not removed after stopping')
396396
})
397-
398-
it('multiple processes from same command are tracked seperately', async function () {
399-
const childProcess1 = new ChildProcess(getSleepCmd(), ['90'])
400-
const childProcess2 = new ChildProcess(getSleepCmd(), ['90'])
401-
childProcess1.run().catch(() => assert.fail('sleep command threw an error'))
402-
childProcess2.run().catch(() => assert.fail('sleep command threw an error'))
403-
tracker.add(childProcess1)
404-
tracker.add(childProcess2)
405-
406-
assert.strictEqual(tracker.has(childProcess1), true, 'Missing first process')
407-
assert.strictEqual(tracker.has(childProcess2), true, 'Missing second process')
408-
409-
childProcess1.stop()
410-
await clock.tickAsync(ChildProcessTracker.pollingInterval)
411-
assert.strictEqual(tracker.has(childProcess2), true, 'first process was not removed after stopping it')
412-
assert.strictEqual(tracker.size(), 1)
413-
})
397+
for (const _ of Array.from({ length: 1000 })) {
398+
it('multiple processes from same command are tracked seperately', async function () {
399+
const childProcess1 = new ChildProcess(getSleepCmd(), ['90'])
400+
const childProcess2 = new ChildProcess(getSleepCmd(), ['90'])
401+
childProcess1.run().catch(() => assert.fail('sleep command threw an error'))
402+
childProcess2.run().catch(() => assert.fail('sleep command threw an error'))
403+
tracker.add(childProcess1)
404+
tracker.add(childProcess2)
405+
406+
assert.strictEqual(tracker.has(childProcess1), true, 'Missing first process')
407+
assert.strictEqual(tracker.has(childProcess2), true, 'Missing second process')
408+
409+
childProcess1.stop()
410+
await clock.tickAsync(ChildProcessTracker.pollingInterval)
411+
assert.strictEqual(tracker.has(childProcess2), true, 'second process was mistakenly removed')
412+
assert.strictEqual(tracker.has(childProcess1), false, 'first process was not removed after stopping it')
413+
})
414+
}
414415

415416
it('logs a warning message when system usage exceeds threshold', async function () {
416417
const childProcess = new ChildProcess(getSleepCmd(), ['90'])

0 commit comments

Comments
 (0)