0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-29 23:16:30 +01:00
nodejs/test/pummel/test-hash-seed.js
Rich Trott 1a3c7473ec test: use Promise.all() in test-hash-seed
We have several tests where a number of asynchronous processes need to
finish before some checks happen. These are done in a number of ways,
including (as here) using our Countdown testing module. I think
Promise.all() may be the idiomatic and ergonomic way to go for a lot of
these tests. Using this one to get feedback on the idea.

PR-URL: https://github.com/nodejs/node/pull/32273
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
2020-03-17 18:29:56 -07:00

27 lines
905 B
JavaScript

'use strict';
// Check that spawn child doesn't create duplicated entries
const common = require('../common');
const kRepetitions = 2;
const assert = require('assert');
const fixtures = require('../common/fixtures');
const { promisify, debuglog } = require('util');
const debug = debuglog('test');
const { execFile } = require('child_process');
const execFilePromise = promisify(execFile);
const targetScript = fixtures.path('guess-hash-seed.js');
const requiredCallback = common.mustCall((results) => {
const seeds = results.map((val) => val.stdout.trim());
debug(`Seeds: ${seeds}`);
assert.strictEqual(new Set(seeds).size, seeds.length);
assert.strictEqual(seeds.length, kRepetitions);
});
const generateSeed = () => execFilePromise(process.execPath, [targetScript]);
const subprocesses = [...new Array(kRepetitions)].map(generateSeed);
Promise.all(subprocesses)
.then(requiredCallback);