node/test/parallel/test-resource-usage.js
cjihrig 492037ab80
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>
2019-07-03 10:54:07 -04:00

31 lines
671 B
JavaScript

'use strict';
require('../common');
const assert = require('assert');
const rusage = process.resourceUsage();
const fields = [
'userCPUTime',
'systemCPUTime',
'maxRSS',
'sharedMemorySize',
'unsharedDataSize',
'unsharedStackSize',
'minorPageFault',
'majorPageFault',
'swappedOut',
'fsRead',
'fsWrite',
'ipcSent',
'ipcReceived',
'signalsCount',
'voluntaryContextSwitches',
'involuntaryContextSwitches'
];
assert.deepStrictEqual(Object.keys(rusage).sort(), fields.sort());
fields.forEach((n) => {
assert.strictEqual(typeof rusage[n], 'number', `${n} should be a number`);
assert(rusage[n] >= 0, `${n} should be above or equal 0`);
});