Skip to content

Commit

Permalink
refactored comments in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
svetlanabrennan committed Dec 10, 2024
1 parent 9c5147f commit 3ee289c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 30 deletions.
46 changes: 22 additions & 24 deletions tests/unit/gc-metrics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const test = require('node:test')
const assert = require('node:assert')

test('GC Metrics', async (t) => {
test('GC Metrics', async () => {
const metricEmitter = require('../..')()

global.gc()
Expand All @@ -18,27 +18,25 @@ test('GC Metrics', async (t) => {
assert.ok(keys.length > 0, 'should notice at least one GC')
assert.equal(typeof keys[0], 'string', 'should have strings as keys')

await t.test('GC stats objects', () => {
const stats = gcs[keys[0]]
assert.equal(typeof stats, 'object', 'should have stats objects')
assert.equal(typeof stats.typeId, 'number', 'should have the type ID')
assert.equal(typeof stats.type, 'string', 'should have the type name')
assert.equal(typeof stats.metrics, 'object', 'should have a metrics object')
})

await t.test('GC stats metrics', () => {
const metrics = gcs[keys[0]].metrics
assert.equal(typeof metrics.total, 'number', 'should have total field')
assert.equal(typeof metrics.min, 'number', 'should have min field')
assert.equal(typeof metrics.max, 'number', 'should have max field')
assert.equal(typeof metrics.sumOfSquares, 'number', 'should have sumOfSquares field')
assert.equal(typeof metrics.count, 'number', 'should have count field')

assert.ok(metrics.total > 0, 'should have reasonable values for total')
assert.ok(metrics.min > 0, 'should have reasonable values for min')
assert.ok(metrics.max > 0, 'should have reasonable values for max')
assert.ok(metrics.max >= metrics.min, 'should have a max larger than a min')
assert.ok(metrics.sumOfSquares > 0, 'should have reasonable values for sumOfSquares')
assert.ok(metrics.count > 0, 'should have reasonable values for count')
})
// GC stats objects
const stats = gcs[keys[0]]
assert.equal(typeof stats, 'object', 'should have stats objects')
assert.equal(typeof stats.typeId, 'number', 'should have the type ID')
assert.equal(typeof stats.type, 'string', 'should have the type name')
assert.equal(typeof stats.metrics, 'object', 'should have a metrics object')

// GC stats metrics
const metrics = gcs[keys[0]].metrics
assert.equal(typeof metrics.total, 'number', 'should have total field')
assert.equal(typeof metrics.min, 'number', 'should have min field')
assert.equal(typeof metrics.max, 'number', 'should have max field')
assert.equal(typeof metrics.sumOfSquares, 'number', 'should have sumOfSquares field')
assert.equal(typeof metrics.count, 'number', 'should have count field')

assert.ok(metrics.total > 0, 'should have reasonable values for total')
assert.ok(metrics.min > 0, 'should have reasonable values for min')
assert.ok(metrics.max > 0, 'should have reasonable values for max')
assert.ok(metrics.max >= metrics.min, 'should have a max larger than a min')
assert.ok(metrics.sumOfSquares > 0, 'should have reasonable values for sumOfSquares')
assert.ok(metrics.count > 0, 'should have reasonable values for count')
})
8 changes: 2 additions & 6 deletions tests/unit/loop-metrics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ test('Loop Metrics', async (t) => {
// Queue up a loop with some CPU burn.
await new Promise((resolve) => setTimeout(resolve, 100))

console.log('spinning cpu...')
// spinning cpu...
const start = Date.now()
while (Date.now() - start < SPIN_TIME) {} // Spin the CPU for 2 seconds.

Expand All @@ -59,11 +59,7 @@ test('Loop Metrics', async (t) => {
const usage = metric.usage

const meanTime = usage.total / usage.count
if (process.arch === 'arm64') {
console.log(
`{ min: ${usage.min}, max: ${usage.max}, meanTime: ${meanTime}, count: ${usage.count}, total: ${usage.total} }`
)
}

assert.ok(
usage.total * MICRO_TO_MILLIS > SPIN_TIME - CPU_EPSILON,
'should have total greater than spin time'
Expand Down

0 comments on commit 3ee289c

Please sign in to comment.