Skip to content

Commit

Permalink
test: prepare test-hash-seed for CI
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Trott committed Jan 16, 2019
1 parent 0f4cc9a commit 6f00801
Showing 1 changed file with 19 additions and 8 deletions.
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; });

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

0 comments on commit 6f00801

Please sign in to comment.