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 committed 2017-03-28 03:18:44 +03:00
1 parent 66e7dc5587
commit 642baf4699
2 files changed
+5 -1

No files matched your search

+3
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;
+2 -1
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);