summaryrefslogtreecommitdiff
path: root/test/pummel/test-hash-seed.js
blob: 2b7f13593a9aa4f96ecefc64b0ceb6ec1c617901 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'use strict';

// 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 { 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) {
  let result = '';
  const subprocess = spawn(process.execPath, [targetScript]);
  subprocess.stdout.setEncoding('utf8');
  subprocess.stdout.on('data', (data) => { result += data; });

  subprocess.on('exit', () => {
    seeds.push(result.trim());
    countdown.dec();
  });
}