From 7feb99455ab5185cb11c7fe6988b621c8863ada6 Mon Sep 17 00:00:00 2001 From: Ian Perkins Date: Fri, 18 Aug 2017 12:09:57 +0100 Subject: [PATCH] benchmark: fix issues in dns benchmark The benchmark script for dns contained functions with args declared but never used. This fix removes those arguments from the function signatures. No test existed for the dns benchmark so one was added to the parallel suite. To improve performance the tests are limited to 1 invocation to a single endpoint. PR-URL: https://github.com/nodejs/node/pull/14936 Reviewed-By: Rich Trott Reviewed-By: Ruben Bridgewater Reviewed-By: Refael Ackermann --- benchmark/dns/lookup.js | 8 ++++---- test/parallel/test-benchmark-dns.js | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 test/parallel/test-benchmark-dns.js diff --git a/benchmark/dns/lookup.js b/benchmark/dns/lookup.js index ebe9d05695ef23..bb562d528c5b37 100644 --- a/benchmark/dns/lookup.js +++ b/benchmark/dns/lookup.js @@ -5,20 +5,20 @@ const lookup = require('dns').lookup; const bench = common.createBenchmark(main, { name: ['', '127.0.0.1', '::1'], - all: [true, false], + all: ['true', 'false'], n: [5e6] }); function main(conf) { const name = conf.name; const n = +conf.n; - const all = !!conf.all; + const all = conf.all === 'true' ? true : false; var i = 0; if (all) { const opts = { all: true }; bench.start(); - (function cb(err, results) { + (function cb() { if (i++ === n) { bench.end(n); return; @@ -27,7 +27,7 @@ function main(conf) { })(); } else { bench.start(); - (function cb(err, result) { + (function cb() { if (i++ === n) { bench.end(n); return; diff --git a/test/parallel/test-benchmark-dns.js b/test/parallel/test-benchmark-dns.js new file mode 100644 index 00000000000000..ba15ad8c0d2fa9 --- /dev/null +++ b/test/parallel/test-benchmark-dns.js @@ -0,0 +1,27 @@ +'use strict'; + +require('../common'); + +// Minimal test for dns benchmarks. This makes sure the benchmarks aren't +// horribly broken but nothing more than that. + +const assert = require('assert'); +const fork = require('child_process').fork; +const path = require('path'); + +const runjs = path.join(__dirname, '..', '..', 'benchmark', 'run.js'); + +const env = Object.assign({}, process.env, + { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); + +const child = fork(runjs, + ['--set', 'n=1', + '--set', 'all=false', + '--set', 'name=127.0.0.1', + 'dns'], + { env }); + +child.on('exit', (code, signal) => { + assert.strictEqual(code, 0); + assert.strictEqual(signal, null); +});