Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
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: #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>
- Loading branch information
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @@ -1,31 +1,26 @@ | ||
| '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); |