Skip to content
Permalink
Browse files

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: #28498
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information...
cjihrig authored and targos committed Jul 1, 2019
1 parent f3f51e4 commit e4f1e909e1d64be0c29e9baf6fa9e56d2661e889
Showing with 6 additions and 3 deletions.
  1. +6 −3 test/parallel/test-resource-usage.js
@@ -3,8 +3,7 @@ require('../common');
const assert = require('assert');

const rusage = process.resourceUsage();

[
const fields = [
'userCPUTime',
'systemCPUTime',
'maxRSS',
@@ -21,7 +20,11 @@ const rusage = process.resourceUsage();
'signalsCount',
'voluntaryContextSwitches',
'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(rusage[n] >= 0, `${n} should be above or equal 0`);
});

0 comments on commit e4f1e90

Please sign in to comment.
You can’t perform that action at this time.