diff --git a/lib/support/cpuStability.js b/lib/support/cpuStability.js index 57259bb46..74c246c9a 100644 --- a/lib/support/cpuStability.js +++ b/lib/support/cpuStability.js @@ -39,14 +39,15 @@ export async function sampleCpu() { export function getCpuStability(start, end) { const total = end.total - start.total; - return { + const stability = { stealPercent: total > 0 ? Number((((end.steal - start.steal) / total) * 100).toFixed(2)) - : 0, - throttleCount: - start.throttleCount === undefined || end.throttleCount === undefined - ? undefined - : end.throttleCount - start.throttleCount + : 0 }; + // Leave the key out, the statistics log an error for undefined values + if (start.throttleCount !== undefined && end.throttleCount !== undefined) { + stability.throttleCount = end.throttleCount - start.throttleCount; + } + return stability; } diff --git a/test/unittests/cpuStabilityTest.js b/test/unittests/cpuStabilityTest.js index 04d452c6c..9796f8d0f 100644 --- a/test/unittests/cpuStabilityTest.js +++ b/test/unittests/cpuStabilityTest.js @@ -21,8 +21,7 @@ test('Give the steal time and throttle events between two samples', t => { test('Give no throttle events when the CPU does not report them', t => { const start = { total: 1000, steal: 0, throttleCount: undefined }; const end = { total: 1000, steal: 0, throttleCount: undefined }; - t.deepEqual(getCpuStability(start, end), { - stealPercent: 0, - throttleCount: undefined - }); + const stability = getCpuStability(start, end); + t.deepEqual(stability, { stealPercent: 0 }); + t.false('throttleCount' in stability); });