From 3ee289cf15f554cbf9e399ec01b3211ebbf37ea0 Mon Sep 17 00:00:00 2001 From: Svetlana Brennan <50715937+svetlanabrennan@users.noreply.github.com> Date: Tue, 10 Dec 2024 13:42:26 -0600 Subject: [PATCH] refactored comments in unit tests --- tests/unit/gc-metrics.test.js | 46 ++++++++++++++++----------------- tests/unit/loop-metrics.test.js | 8 ++---- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/tests/unit/gc-metrics.test.js b/tests/unit/gc-metrics.test.js index 10937c4..0da8001 100644 --- a/tests/unit/gc-metrics.test.js +++ b/tests/unit/gc-metrics.test.js @@ -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() @@ -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') }) diff --git a/tests/unit/loop-metrics.test.js b/tests/unit/loop-metrics.test.js index 094896c..60af5fe 100644 --- a/tests/unit/loop-metrics.test.js +++ b/tests/unit/loop-metrics.test.js @@ -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. @@ -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'