test: increase test-resource-usage.js validation
This commit adds an assertion checking the exact field names returned by process.resourceUsage(). This ensures that no new fields accidentally slip into the returned object in the future. PR-URL: https://github.com/nodejs/node/pull/28498 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
parent
fcf8fe9f1a
commit
492037ab80
@ -3,8 +3,7 @@ require('../common');
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
const rusage = process.resourceUsage();
|
const rusage = process.resourceUsage();
|
||||||
|
const fields = [
|
||||||
[
|
|
||||||
'userCPUTime',
|
'userCPUTime',
|
||||||
'systemCPUTime',
|
'systemCPUTime',
|
||||||
'maxRSS',
|
'maxRSS',
|
||||||
@ -21,7 +20,11 @@ const rusage = process.resourceUsage();
|
|||||||
'signalsCount',
|
'signalsCount',
|
||||||
'voluntaryContextSwitches',
|
'voluntaryContextSwitches',
|
||||||
'involuntaryContextSwitches'
|
'involuntaryContextSwitches'
|
||||||
].forEach((n) => {
|
];
|
||||||
|
|
||||||
|
assert.deepStrictEqual(Object.keys(rusage).sort(), fields.sort());
|
||||||
|
|
||||||
|
fields.forEach((n) => {
|
||||||
assert.strictEqual(typeof rusage[n], 'number', `${n} should be a number`);
|
assert.strictEqual(typeof rusage[n], 'number', `${n} should be a number`);
|
||||||
assert(rusage[n] >= 0, `${n} should be above or equal 0`);
|
assert(rusage[n] >= 0, `${n} should be above or equal 0`);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user