Permalink
Browse files

benchmark: check end() argument to be > 0

PR-URL: #12030
Ref: #11972
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information...
vsemozhetbyt committed Mar 24, 2017
1 parent 66e7dc5 commit 642baf4699c3a973c073403a7f1a4c85e0197e81
Showing with 5 additions and 1 deletion.
  1. +3 −0 benchmark/common.js
  2. +2 −1 test/sequential/test-benchmark-net.js
View
@@ -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;
@@ -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);

0 comments on commit 642baf4

Please sign in to comment.