From 492037ab801391b0a86d1cc1204a5f14d5b74641 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Mon, 1 Jul 2019 10:38:08 -0400 Subject: [PATCH] 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 Reviewed-By: Trivikram Kamat Reviewed-By: Rich Trott --- test/parallel/test-resource-usage.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-resource-usage.js b/test/parallel/test-resource-usage.js index 25302b8413fda4..ff41452f4a7f3b 100644 --- a/test/parallel/test-resource-usage.js +++ b/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`); });