Skip to content

Commit

Permalink
benchmark: check end() argument to be > 0
Browse files Browse the repository at this point in the history
PR-URL: #12030
Ref: #11972
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
  • Loading branch information
vsemozhetbyt authored and MylesBorins committed Mar 28, 2017
1 parent 8b2b93f commit 751c115
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions benchmark/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion test/sequential/test-benchmark-net.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 751c115

Please sign in to comment.