From 0f4cc9a5712ebb50c8d9b878cee607ea3977b399 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 15 Jan 2019 10:04:34 -0800 Subject: [PATCH 1/2] test: refactor min() in test-hash-seed Replace min() function with Math.min(...). --- test/fixtures/guess-hash-seed.js | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/test/fixtures/guess-hash-seed.js b/test/fixtures/guess-hash-seed.js index ffcfd75aac54a3..8d69cf92490d20 100644 --- a/test/fixtures/guess-hash-seed.js +++ b/test/fixtures/guess-hash-seed.js @@ -1,13 +1,4 @@ 'use strict'; -function min(arr) { - let res = arr[0]; - for (let i = 1; i < arr.length; i++) { - const val = arr[i]; - if (val < res) - res = val; - } - return res; -} function run_repeated(n, fn) { const res = []; for (let i = 0; i < n; i++) res.push(fn()); @@ -118,11 +109,11 @@ let tester_set_treshold; // calibrate Set access times for accessing the full bucket / an empty bucket const pos_time = - min(run_repeated(10000, time_set_lookup.bind(null, tester_set, - positive_test_value))); + Math.min(...run_repeated(10000, time_set_lookup.bind(null, tester_set, + positive_test_value))); const neg_time = - min(run_repeated(10000, time_set_lookup.bind(null, tester_set, - negative_test_value))); + Math.min(...run_repeated(10000, time_set_lookup.bind(null, tester_set, + negative_test_value))); tester_set_treshold = (pos_time + neg_time) / 2; // console.log(`pos_time: ${pos_time}, neg_time: ${neg_time},`, // `threshold: ${tester_set_treshold}`); From 6f008013a493ed5aeae28cbecbefdbf5ce4ec1f0 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 15 Jan 2019 10:31:12 -0800 Subject: [PATCH 2/2] test: prepare test-hash-seed for CI Reduce the time it takes to run test/pummel/test-hash-seed by switching from spawnSync() to spawn(). On my computer, this reduces the runtime from about 80 seconds to about 40 seconds. This test is not (yet) run regularly on CI, but when it was run recently, it timed out. --- test/pummel/test-hash-seed.js | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/test/pummel/test-hash-seed.js b/test/pummel/test-hash-seed.js index fd59bbe5e0653c..2b7f13593a9aa4 100644 --- a/test/pummel/test-hash-seed.js +++ b/test/pummel/test-hash-seed.js @@ -2,19 +2,30 @@ // Check that spawn child doesn't create duplicated entries require('../common'); +const Countdown = require('../common/countdown'); const REPETITIONS = 2; const assert = require('assert'); const fixtures = require('../common/fixtures'); -const { spawnSync } = require('child_process'); +const { spawn } = require('child_process'); const targetScript = fixtures.path('guess-hash-seed.js'); const seeds = []; +const requiredCallback = () => { + console.log(`Seeds: ${seeds}`); + assert.strictEqual(new Set(seeds).size, seeds.length); + assert.strictEqual(seeds.length, REPETITIONS); +}; + +const countdown = new Countdown(REPETITIONS, requiredCallback); + for (let i = 0; i < REPETITIONS; ++i) { - const seed = spawnSync(process.execPath, [targetScript], { - encoding: 'utf8' - }).stdout.trim(); - seeds.push(seed); -} + let result = ''; + const subprocess = spawn(process.execPath, [targetScript]); + subprocess.stdout.setEncoding('utf8'); + subprocess.stdout.on('data', (data) => { result += data; }); -console.log(`Seeds: ${seeds}`); -assert.strictEqual(new Set(seeds).size, seeds.length); + subprocess.on('exit', () => { + seeds.push(result.trim()); + countdown.dec(); + }); +}