Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: reduce test-hash-seed run time by half #25522

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions test/fixtures/guess-hash-seed.js
Original file line number Diff line number Diff line change
@@ -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());
Expand Down Expand Up @@ -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}`);
Expand Down
27 changes: 19 additions & 8 deletions test/pummel/test-hash-seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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; });
Trott marked this conversation as resolved.
Show resolved Hide resolved

console.log(`Seeds: ${seeds}`);
assert.strictEqual(new Set(seeds).size, seeds.length);
subprocess.on('exit', () => {
seeds.push(result.trim());
countdown.dec();
});
}