Refactor parallel tests (#1084)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 7143492 · Browse files · 8 files·+19 added−21 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
8 files+19 added−21 removed
- tests:+18 added−21 removed
- other:+1 added−0 removed
Provenance
- Commit
5cf6312- Tree
f9c1f2f- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
7143492
8 files changed+19 added−21 removed
added:test/helpers/parallel.js+3 added
123import isInCi from 'is-in-ci';
export const PARALLEL_COUNT = isInCi ? 10 : 100;modified:test/io/output-async.js+3 added-4 removed
5 unmodified lines6789101112131424 unmodified lines39404142424343444645464748495 unmodified lines5556575860596061626320 unmodified lines5 unmodified linesimport {STANDARD_STREAMS} from '../helpers/stdio.js';import {foobarString} from '../helpers/input.js';import {setFixtureDirectory} from '../helpers/fixtures-directory.js';import {assertMaxListeners} from '../helpers/listeners.js';import {PARALLEL_COUNT} from '../helpers/parallel.js';
setFixtureDirectory();
const getStandardStreamListeners = stream => Object.fromEntries(stream.eventNames().map(eventName => [eventName, stream.listeners(eventName)]));24 unmodified lines
test.serial('process.std* listeners are cleaned up on success with a single input', testListenersCleanup, false);test.serial('process.std* listeners are cleaned up on success with multiple inputs', testListenersCleanup, true);
const subprocessesCount = 100;
test.serial('Can spawn many subprocesses in parallel', async t => { const results = await Promise.all( Array.from({length: subprocessesCount}, () => execa('noop.js', [foobarString])), Array.from({length: PARALLEL_COUNT}, () => execa('noop.js', [foobarString])), ); t.true(results.every(({stdout}) => stdout === foobarString));});
5 unmodified lines }
try { const results = await Promise.all( Array.from({length: subprocessesCount}, () => execa('empty.js', getComplexStdio(isMultiple))), Array.from({length: PARALLEL_COUNT}, () => execa('empty.js', getComplexStdio(isMultiple))), ); t.true(results.every(({exitCode}) => exitCode === 0)); } finally { await setImmediate();20 unmodified linesmodified:test/ipc/buffer-messages.js+2 added-3 removed
12345678947 unmodified lines575859606061616264636465666712 unmodified linesimport test from 'ava';import {execa, execaSync} from '../../index.js';import {setFixtureDirectory} from '../helpers/fixtures-directory.js';import {foobarString, foobarArray} from '../helpers/input.js';import {PARALLEL_COUNT} from '../helpers/parallel.js';
setFixtureDirectory();
const testResultIpc = async (t, options) => {47 unmodified lines const {ipcOutput} = t.throws(() => execaSync('fail.js')); t.deepEqual(ipcOutput, []);});
const HIGH_CONCURRENCY_COUNT = 10;
test.serial('Can retrieve initial IPC messages under heavy load', async t => { await Promise.all( Array.from({length: HIGH_CONCURRENCY_COUNT}, async (_, index) => { Array.from({length: PARALLEL_COUNT}, async (_, index) => { const {ipcOutput} = await execa('ipc-send-argv.js', [`${index}`], {ipc: true}); t.deepEqual(ipcOutput, [`${index}`]); }), );12 unmodified linesmodified:test/ipc/get-each.js+3 added-4 removed
1 unmodified line2 import {execa} from '../../index.js';3 import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4 import {foobarString, foobarArray} from '../helpers/input.js';5 import {iterateAllMessages} from '../helpers/ipc.js';6+import {PARALLEL_COUNT} from '../helpers/parallel.js';7 8 setFixtureDirectory();9 10 test('Can iterate over IPC messages', async t => {71 unmodified lines82 const {ipcOutput} = await subprocess;83 t.deepEqual(ipcOutput, [foobarString]);84 });85 85-const HIGH_CONCURRENCY_COUNT = 10;86-86 test.serial('Can send many messages at once with exports.getEachMessage()', async t => {87 const subprocess = execa('ipc-iterate.js', {ipc: true});89- await Promise.all(Array.from({length: HIGH_CONCURRENCY_COUNT}, (_, index) => subprocess.sendMessage(index)));88+ await Promise.all(Array.from({length: PARALLEL_COUNT}, (_, index) => subprocess.sendMessage(index)));89 await subprocess.sendMessage(foobarString);90 91 const {ipcOutput} = await subprocess;93- t.deepEqual(ipcOutput, Array.from({length: HIGH_CONCURRENCY_COUNT}, (_, index) => index));92+ t.deepEqual(ipcOutput, Array.from({length: PARALLEL_COUNT}, (_, index) => index));93 });94 95 test('Disconnecting in the current process stops exports.getEachMessage()', async t => {96 const subprocess = execa('ipc-iterate-print.js', {ipc: true});83 unmodified linesmodified:test/ipc/get-one.js+2 added-3 removed
8 unmodified lines9 subprocessSendGetOne,10 subprocessExchange,11 alwaysPass,12 } from '../helpers/ipc.js';13+import {PARALLEL_COUNT} from '../helpers/parallel.js';14 15 setFixtureDirectory();16 17 const testKeepAlive = async (t, buffer, exchangeMethod) => {62 unmodified lines80 81 test('exports.getOneMessage() can filter messages', testFilterSubprocess, 'ipc-echo-filter.js', [foobarArray[1]]);82 test('exports.exchangeMessage() can filter messages', testFilterSubprocess, 'ipc-echo-filter-exchange.js', ['.', foobarArray[1]]);83 83-const HIGH_CONCURRENCY_COUNT = 10;84-84 const testHeavyLoad = async (t, exchangeMethod) => {85 await Promise.all(87- Array.from({length: HIGH_CONCURRENCY_COUNT}, async (_, index) => {86+ Array.from({length: PARALLEL_COUNT}, async (_, index) => {87 const subprocess = execa('ipc-send-argv.js', [`${index}`], {ipc: true, buffer: false});88 t.is(await exchangeMethod(subprocess, {}), `${index}`);89 await subprocess;90 }),149 unmodified linesmodified:test/ipc/send.js+2 added-3 removed
1 unmodified line2 import {execa} from '../../index.js';3 import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4 import {foobarString} from '../helpers/input.js';5 import {subprocessSendGetOne, subprocessExchange} from '../helpers/ipc.js';6+import {PARALLEL_COUNT} from '../helpers/parallel.js';7 8 setFixtureDirectory();9 10 const testExchange = async (t, exchangeMethod) => {4 unmodified lines15 16 test('Can exchange IPC messages', testExchange, subprocessSendGetOne);17 test('Can exchange IPC messages, exchangeMessage()', testExchange, subprocessExchange);18 18-const HIGH_CONCURRENCY_COUNT = 10;19-19 const testHeavyLoad = async (t, exchangeMethod) => {20 await Promise.all(22- Array.from({length: HIGH_CONCURRENCY_COUNT}, async (_, index) => {21+ Array.from({length: PARALLEL_COUNT}, async (_, index) => {22 const subprocess = execa('ipc-echo.js', {ipc: true});23 t.is(await exchangeMethod(subprocess, index), index);24 await subprocess;25 }),77 unmodified linesmodified:test/pipe/streaming.js+3 added-4 removed
4 unmodified lines5 import {setFixtureDirectory} from '../helpers/fixtures-directory.js';6 import {foobarString} from '../helpers/input.js';7 import {assertMaxListeners} from '../helpers/listeners.js';8 import {fullReadableStdio} from '../helpers/stdio.js';9+import {PARALLEL_COUNT} from '../helpers/parallel.js';10 11 setFixtureDirectory();12 13 test('Can pipe two sources to same destination', async t => {27 unmodified lines41 t.is(await secondPipePromise, await destination);42 t.is(await thirdPromise, await destination);43 });44 44-const subprocessesCount = 100;45-45 test.serial('Can pipe many sources to same destination', async t => {46 const checkMaxListeners = assertMaxListeners(t);47 49- const expectedResults = Array.from({length: subprocessesCount}, (_, index) => `${index}`).sort();48+ const expectedResults = Array.from({length: PARALLEL_COUNT}, (_, index) => `${index}`).sort();49 const sources = expectedResults.map(expectedResult => execa('noop.js', [expectedResult]));50 const destination = execa('stdin.js');51 const pipePromises = sources.map(source => source.pipe(destination));52 9 unmodified lines62 test.serial('Can pipe same source to many destinations', async t => {63 const checkMaxListeners = assertMaxListeners(t);64 65 const source = execa('noop-fd.js', ['1', foobarString]);67- const expectedResults = Array.from({length: subprocessesCount}, (_, index) => `${index}`);66+ const expectedResults = Array.from({length: PARALLEL_COUNT}, (_, index) => `${index}`);67 const destinations = expectedResults.map(expectedResult => execa('noop-stdin-double.js', [expectedResult]));68 const pipePromises = destinations.map(destination => source.pipe(destination));69 70 t.like(await source, {stdout: foobarString});370 unmodified linesmodified:package.json+1 added
67 unmodified lines68 "@types/node": "^20.8.9",69 "ava": "^6.0.1",70 "c8": "^9.1.0",71 "get-node": "^15.0.0",72+ "is-in-ci": "^0.1.0",73 "is-running": "^2.1.0",74 "path-exists": "^5.0.0",75 "path-key": "^4.0.0",76 "tempfile": "^5.0.0",28 unmodified lines