summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2021-12-11 16:59:48 -0800
committerJames M Snell <jasnell@gmail.com>2021-12-19 09:56:36 -0800
commit23637e9a3b208892449268290143dad4391fee45 (patch)
treec8f83283bb0d357b7db22298e217cbe5e877a656 /test
parent665b404e6512c6fdfe811e793d4f14bf8f8a7d36 (diff)
downloadnode-new-23637e9a3b208892449268290143dad4391fee45.tar.gz
perf_hooks: multiple fixes for Histogram
* The createHistogram(options) options weren't actually implemented * Add a new count property that tracks the number of samples * Adds BigInt options for relevant properties * Adds add(other) method for RecordableHistogram * Cleans up and expands tests * Eliminates unnecessary ELDHistogram native class * Improve/Simplify histogram transfer impl Signed-off-by: James M Snell <jasnell@gmail.com> perf_hooks: simplify Histogram constructor options Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: https://github.com/nodejs/node/pull/41153 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-perf-hooks-histogram.js133
1 files changed, 105 insertions, 28 deletions
diff --git a/test/parallel/test-perf-hooks-histogram.js b/test/parallel/test-perf-hooks-histogram.js
index a60d3a94bb..2137c1b2a3 100644
--- a/test/parallel/test-perf-hooks-histogram.js
+++ b/test/parallel/test-perf-hooks-histogram.js
@@ -1,54 +1,75 @@
'use strict';
const common = require('../common');
-const assert = require('assert');
+
+const {
+ ok,
+ strictEqual,
+ throws,
+} = require('assert');
+
const {
createHistogram,
monitorEventLoopDelay,
} = require('perf_hooks');
+
const { inspect } = require('util');
{
const h = createHistogram();
- assert.strictEqual(h.min, 9223372036854776000);
- assert.strictEqual(h.max, 0);
- assert.strictEqual(h.exceeds, 0);
- assert(Number.isNaN(h.mean));
- assert(Number.isNaN(h.stddev));
+ strictEqual(h.min, 9223372036854776000);
+ strictEqual(h.minBigInt, 9223372036854775807n);
+ strictEqual(h.max, 0);
+ strictEqual(h.maxBigInt, 0n);
+ strictEqual(h.exceeds, 0);
+ strictEqual(h.exceedsBigInt, 0n);
+ ok(Number.isNaN(h.mean));
+ ok(Number.isNaN(h.stddev));
+
+ strictEqual(h.count, 0);
+ strictEqual(h.countBigInt, 0n);
h.record(1);
+ strictEqual(h.count, 1);
+ strictEqual(h.countBigInt, 1n);
+
[false, '', {}, undefined, null].forEach((i) => {
- assert.throws(() => h.record(i), {
+ throws(() => h.record(i), {
code: 'ERR_INVALID_ARG_TYPE'
});
});
- assert.throws(() => h.record(0, Number.MAX_SAFE_INTEGER + 1), {
+ throws(() => h.record(0, Number.MAX_SAFE_INTEGER + 1), {
code: 'ERR_OUT_OF_RANGE'
});
- assert.strictEqual(h.min, 1);
- assert.strictEqual(h.max, 1);
- assert.strictEqual(h.exceeds, 0);
- assert.strictEqual(h.mean, 1);
- assert.strictEqual(h.stddev, 0);
+ strictEqual(h.min, 1);
+ strictEqual(h.minBigInt, 1n);
+ strictEqual(h.max, 1);
+ strictEqual(h.maxBigInt, 1n);
+ strictEqual(h.exceeds, 0);
+ strictEqual(h.mean, 1);
+ strictEqual(h.stddev, 0);
+
+ strictEqual(h.percentile(1), 1);
+ strictEqual(h.percentile(100), 1);
- assert.strictEqual(h.percentile(1), 1);
- assert.strictEqual(h.percentile(100), 1);
+ strictEqual(h.percentileBigInt(1), 1n);
+ strictEqual(h.percentileBigInt(100), 1n);
const mc = new MessageChannel();
mc.port1.onmessage = common.mustCall(({ data }) => {
- assert.strictEqual(h.min, 1);
- assert.strictEqual(h.max, 1);
- assert.strictEqual(h.exceeds, 0);
- assert.strictEqual(h.mean, 1);
- assert.strictEqual(h.stddev, 0);
+ strictEqual(h.min, 1);
+ strictEqual(h.max, 1);
+ strictEqual(h.exceeds, 0);
+ strictEqual(h.mean, 1);
+ strictEqual(h.stddev, 0);
data.record(2n);
data.recordDelta();
- assert.strictEqual(h.max, 2);
+ strictEqual(h.max, 2);
mc.port1.close();
});
@@ -57,13 +78,15 @@ const { inspect } = require('util');
{
const e = monitorEventLoopDelay();
+ strictEqual(e.count, 0);
e.enable();
const mc = new MessageChannel();
mc.port1.onmessage = common.mustCall(({ data }) => {
- assert(typeof data.min, 'number');
- assert(data.min > 0);
- assert.strictEqual(data.disable, undefined);
- assert.strictEqual(data.enable, undefined);
+ strictEqual(typeof data.min, 'number');
+ ok(data.min > 0);
+ ok(data.count > 0);
+ strictEqual(data.disable, undefined);
+ strictEqual(data.enable, undefined);
mc.port1.close();
});
setTimeout(() => mc.port2.postMessage(e), 100);
@@ -71,12 +94,66 @@ const { inspect } = require('util');
{
const h = createHistogram();
- assert(inspect(h, { depth: null }).startsWith('Histogram'));
- assert.strictEqual(inspect(h, { depth: -1 }), '[RecordableHistogram]');
+ ok(inspect(h, { depth: null }).startsWith('Histogram'));
+ strictEqual(inspect(h, { depth: -1 }), '[RecordableHistogram]');
}
{
// Tests that RecordableHistogram is impossible to construct manually
const h = createHistogram();
- assert.throws(() => new h.constructor(), { code: 'ERR_ILLEGAL_CONSTRUCTOR' });
+ throws(() => new h.constructor(), { code: 'ERR_ILLEGAL_CONSTRUCTOR' });
+}
+
+{
+ [
+ 'hello',
+ 1,
+ null,
+ ].forEach((i) => {
+ throws(() => createHistogram(i), { code: 'ERR_INVALID_ARG_TYPE' });
+ });
+
+ [
+ 'hello',
+ false,
+ null,
+ {},
+ ].forEach((i) => {
+ throws(() => createHistogram({ lowest: i }), {
+ code: 'ERR_INVALID_ARG_TYPE',
+ });
+ throws(() => createHistogram({ highest: i }), {
+ code: 'ERR_INVALID_ARG_TYPE',
+ });
+ throws(() => createHistogram({ figures: i }), {
+ code: 'ERR_INVALID_ARG_TYPE',
+ });
+ });
+
+ createHistogram({ lowest: 1, highest: 11, figures: 1 });
+}
+
+{
+ const h1 = createHistogram();
+ const h2 = createHistogram();
+
+ h1.record(1);
+
+ strictEqual(h2.count, 0);
+ strictEqual(h1.count, 1);
+
+ h2.add(h1);
+
+ strictEqual(h2.count, 1);
+
+ [
+ 'hello',
+ 1,
+ false,
+ {},
+ ].forEach((i) => {
+ throws(() => h1.add(i), {
+ code: 'ERR_INVALID_ARG_TYPE',
+ });
+ });
}