Skip to content

Commit

Permalink
test: increase test-resource-usage.js validation
Browse files Browse the repository at this point in the history
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 20, 2019
1 parent f3f51e4 commit e4f1e90
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions test/parallel/test-resource-usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ require('../common');
const assert = require('assert');

const rusage = process.resourceUsage();

[
const fields = [
'userCPUTime',
'systemCPUTime',
'maxRSS',
Expand All @@ -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.