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(); + }); +}