From 9c361aa3673eff98ada601a6dc23fdba036dd71b Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Sat, 25 Mar 2017 01:12:51 +0200 Subject: [PATCH] benchmark: check end() argument to be > 0 Refs: https://github.com/nodejs/node/issues/11972 --- benchmark/common.js | 3 +++ test/sequential/test-benchmark-net.js | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/benchmark/common.js b/benchmark/common.js index 24369f2f543b67..77ebe0bd1dc37f 100644 --- a/benchmark/common.js +++ b/benchmark/common.js @@ -193,6 +193,9 @@ Benchmark.prototype.end = function(operations) { if (typeof operations !== 'number') { throw new Error('called end() without specifying operation count'); } + if (!process.env.NODEJS_BENCHMARK_ZERO_ALLOWED && operations <= 0) { + throw new Error('called end() with operation count <= 0'); + } const time = elapsed[0] + elapsed[1] / 1e9; const rate = operations / time; diff --git a/test/sequential/test-benchmark-net.js b/test/sequential/test-benchmark-net.js index 4bb91451e9b254..826d891fd76621 100644 --- a/test/sequential/test-benchmark-net.js +++ b/test/sequential/test-benchmark-net.js @@ -15,7 +15,8 @@ const path = require('path'); const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js'); -const child = fork(runjs, ['--set', 'dur=0', 'net']); +const child = fork(runjs, ['--set', 'dur=0', 'net'], + {env: {NODEJS_BENCHMARK_ZERO_ALLOWED: 1}}); child.on('exit', (code, signal) => { assert.strictEqual(code, 0); assert.strictEqual(signal, null);