benchmark: check end() argument to be > 0

PR-URL: https://github.com/nodejs/node/pull/12030
Ref: https://github.com/nodejs/node/issues/11972
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
Vse Mozhet Byt 2017-03-25 01:12:51 +02:00
parent 66e7dc5587
commit 642baf4699
2 changed files with 5 additions and 1 deletions

View File

@ -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;

View File

@ -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);