mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
9a275e15c3
This commit exposes a new API to the perf_hooks.performance module. This wraps uv_metrics_info into performance.uvMetricsInfo() function. PR-URL: https://github.com/nodejs/node/pull/54413 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
46 lines
1.3 KiB
JavaScript
46 lines
1.3 KiB
JavaScript
// Enforcing strict checks on the order or number of events across different
|
|
// platforms can be tricky and unreliable due to various factors.
|
|
// As a result, this test relies on the `uv_metrics_info` call instead.
|
|
const { performance } = require('node:perf_hooks');
|
|
const assert = require('node:assert');
|
|
const fs = require('node:fs');
|
|
const { nodeTiming } = performance;
|
|
|
|
function safeMetricsInfo(cb) {
|
|
setImmediate(() => {
|
|
const info = nodeTiming.uvMetricsInfo;
|
|
cb(info);
|
|
});
|
|
}
|
|
|
|
{
|
|
const info = nodeTiming.uvMetricsInfo;
|
|
assert.strictEqual(info.loopCount, 0);
|
|
assert.strictEqual(info.events, 0);
|
|
// This is the only part of the test that we test events waiting
|
|
// Adding checks for this property will make the test flaky
|
|
// as it can be highly influenced by race conditions.
|
|
assert.strictEqual(info.eventsWaiting, 0);
|
|
}
|
|
|
|
{
|
|
// The synchronous call should obviously not affect the uv metrics
|
|
const fd = fs.openSync(__filename, 'r');
|
|
fs.readFileSync(fd);
|
|
const info = nodeTiming.uvMetricsInfo;
|
|
assert.strictEqual(info.loopCount, 0);
|
|
assert.strictEqual(info.events, 0);
|
|
assert.strictEqual(info.eventsWaiting, 0);
|
|
}
|
|
|
|
{
|
|
function openFile(info) {
|
|
assert.strictEqual(info.loopCount, 1);
|
|
|
|
fs.open(__filename, 'r', (err) => {
|
|
assert.ifError(err);
|
|
});
|
|
}
|
|
|
|
safeMetricsInfo(openFile);
|
|
} |