async.js
This file
Path
test/stdio/async.js
84 lines · 4.0 KiB · JavaScript
Last changed by
Fix race condition with `subprocess.stdin.destroy()` (#904)ehmickybefore adoption588bf16
History of this fileTake it
Fix `maxListeners` warning when running multiple processes in parallel (#785)ehmickybefore adoptiond50c4cc
lines 1–2why, one step back1import {once, defaultMaxListeners} from 'node:events';2import process from 'node:process';Fix error handling of `stdin` (#787)ehmickybefore adoption4328670
line 3why, one step back3import {setImmediate} from 'node:timers/promises';Fix `maxListeners` warning when running multiple processes in parallel (#785)ehmickybefore adoptiond50c4cc
lines 4–8why, one step back4import test from 'ava';5import {execa} from '../../index.js';6import {STANDARD_STREAMS} from '../helpers/stdio.js';7import {foobarString} from '../helpers/input.js';8import {setFixtureDir} from '../helpers/fixtures-dir.js';Avoid code duplication with logic related to `maxListeners` (#831)ehmickybefore adoptioncd2a6c0
line 9why, one step back9import {assertMaxListeners} from '../helpers/listeners.js';Fix `maxListeners` warning when running multiple processes in parallel (#785)ehmickybefore adoptiond50c4cc
lines 10–21why, one step back1011setFixtureDir();1213const getStandardStreamListeners = stream => Object.fromEntries(stream.eventNames().map(eventName => [eventName, stream.listeners(eventName)]));14const getStandardStreamsListeners = () => STANDARD_STREAMS.map(stream => getStandardStreamListeners(stream));1516const getComplexStdio = isMultiple => ({17 stdin: ['pipe', 'inherit', ...(isMultiple ? [0, process.stdin] : [])],18 stdout: ['pipe', 'inherit', ...(isMultiple ? [1, process.stdout] : [])],19 stderr: ['pipe', 'inherit', ...(isMultiple ? [2, process.stderr] : [])],20});21Fix race condition with `subprocess.stdin.destroy()` (#904)ehmickybefore adoption588bf16
line 22why, one step back22const onStdinRemoveListener = () => once(process.stdin, 'removeListener');Fix randomly failing tests (#793)ehmickybefore adoption45475e7
line 23why, one step back23Fix `maxListeners` warning when running multiple processes in parallel (#785)ehmickybefore adoptiond50c4cc
lines 24–25why, one step back24const testListenersCleanup = async (t, isMultiple) => {25 const streamsPreviousListeners = getStandardStreamsListeners();Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 26why, one step back26 const subprocess = execa('empty.js', getComplexStdio(isMultiple));Fix `maxListeners` warning when running multiple processes in parallel (#785)ehmickybefore adoptiond50c4cc
line 27why, one step back27 t.notDeepEqual(getStandardStreamsListeners(), streamsPreviousListeners);Fix race condition with `subprocess.stdin.destroy()` (#904)ehmickybefore adoption588bf16
line 28why, one step back28 await Promise.all([subprocess, onStdinRemoveListener()]);Fix randomly failing tests (#793)ehmickybefore adoption45475e7
lines 29–31why, one step back29 if (isMultiple) {30 await onStdinRemoveListener();31 }Fix `maxListeners` warning when running multiple processes in parallel (#785)ehmickybefore adoptiond50c4cc
line 32why, one step back32Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 33why, one step back33 for (const [fdNumber, streamNewListeners] of Object.entries(getStandardStreamsListeners())) {Fix `maxListeners` warning when running multiple processes in parallel (#785)ehmickybefore adoptiond50c4cc
line 34why, one step back34 const defaultListeners = Object.fromEntries(Reflect.ownKeys(streamNewListeners).map(eventName => [eventName, []]));Rename `index` to `fdNumber` (#862)ehmickybefore adoption295ef40
line 35why, one step back35 t.deepEqual(streamNewListeners, {...defaultListeners, ...streamsPreviousListeners[fdNumber]});Fix `maxListeners` warning when running multiple processes in parallel (#785)ehmickybefore adoptiond50c4cc
lines 36–41why, one step back36 }37};3839test.serial('process.std* listeners are cleaned up on success with a single input', testListenersCleanup, false);40test.serial('process.std* listeners are cleaned up on success with multiple inputs', testListenersCleanup, true);41Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 42why, one step back42const subprocessesCount = 100;Fix `maxListeners` warning when running multiple processes in parallel (#785)ehmickybefore adoptiond50c4cc
line 43why, one step back43Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 44why, one step back44test.serial('Can spawn many subprocesses in parallel', async t => {Fix `maxListeners` warning when running multiple processes in parallel (#785)ehmickybefore adoptiond50c4cc
line 45why, one step back45 const results = await Promise.all(Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 46why, one step back46 Array.from({length: subprocessesCount}, () => execa('noop.js', [foobarString])),Fix `maxListeners` warning when running multiple processes in parallel (#785)ehmickybefore adoptiond50c4cc
lines 47–51why, one step back47 );48 t.true(results.every(({stdout}) => stdout === foobarString));49});5051const testMaxListeners = async (t, isMultiple, maxListenersCount) => {Avoid code duplication with logic related to `maxListeners` (#831)ehmickybefore adoptioncd2a6c0
line 52why, one step back52 const checkMaxListeners = assertMaxListeners(t);Fix `maxListeners` warning when running multiple processes in parallel (#785)ehmickybefore adoptiond50c4cc
lines 53–59why, one step back5354 for (const standardStream of STANDARD_STREAMS) {55 standardStream.setMaxListeners(maxListenersCount);56 }5758 try {59 const results = await Promise.all(Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 60why, one step back60 Array.from({length: subprocessesCount}, () => execa('empty.js', getComplexStdio(isMultiple))),Fix `maxListeners` warning when running multiple processes in parallel (#785)ehmickybefore adoptiond50c4cc
lines 61–63why, one step back61 );62 t.true(results.every(({exitCode}) => exitCode === 0));63 } finally {Fix randomly failing tests (#793)ehmickybefore adoption45475e7
lines 64–65why, one step back64 await setImmediate();65 await setImmediate();Avoid code duplication with logic related to `maxListeners` (#831)ehmickybefore adoptioncd2a6c0
line 66why, one step back66 checkMaxListeners();Fix randomly failing tests (#793)ehmickybefore adoption45475e7
line 67why, one step back67Fix `maxListeners` warning when running multiple processes in parallel (#785)ehmickybefore adoptiond50c4cc
lines 68–84why, one step back68 for (const standardStream of STANDARD_STREAMS) {69 t.is(standardStream.getMaxListeners(), maxListenersCount);70 standardStream.setMaxListeners(defaultMaxListeners);71 }72 }73};7475test.serial('No warning with maxListeners 1 and ["pipe", "inherit"]', testMaxListeners, false, 1);76test.serial('No warning with maxListeners default and ["pipe", "inherit"]', testMaxListeners, false, defaultMaxListeners);77test.serial('No warning with maxListeners 100 and ["pipe", "inherit"]', testMaxListeners, false, 100);78test.serial('No warning with maxListeners Infinity and ["pipe", "inherit"]', testMaxListeners, false, Number.POSITIVE_INFINITY);79test.serial('No warning with maxListeners 0 and ["pipe", "inherit"]', testMaxListeners, false, 0);80test.serial('No warning with maxListeners 1 and ["pipe", "inherit"], multiple inputs', testMaxListeners, true, 1);81test.serial('No warning with maxListeners default and ["pipe", "inherit"], multiple inputs', testMaxListeners, true, defaultMaxListeners);82test.serial('No warning with maxListeners 100 and ["pipe", "inherit"], multiple inputs', testMaxListeners, true, 100);83test.serial('No warning with maxListeners Infinity and ["pipe", "inherit"], multiple inputs', testMaxListeners, true, Number.POSITIVE_INFINITY);84test.serial('No warning with maxListeners 0 and ["pipe", "inherit"], multiple inputs', testMaxListeners, true, 0);