Skip to content
Myr

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

8 files+19 added−21 removed

added:test/helpers/parallel.js+3 added
modified:test/io/output-async.js+3 added-4 removed
modified:test/ipc/buffer-messages.js+2 added-3 removed
modified:test/ipc/get-each.js+3 added-4 removed
1 unmodified line
2import {execa} from '../../index.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {foobarString, foobarArray} from '../helpers/input.js';5import {iterateAllMessages} from '../helpers/ipc.js';6import {PARALLEL_COUNT} from '../helpers/parallel.js';78setFixtureDirectory();910test('Can iterate over IPC messages', async t => {
71 unmodified lines
82 const {ipcOutput} = await subprocess;83 t.deepEqual(ipcOutput, [foobarString]);84});8585const HIGH_CONCURRENCY_COUNT = 10;8686test.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);9091 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});9495test('Disconnecting in the current process stops exports.getEachMessage()', async t => {96 const subprocess = execa('ipc-iterate-print.js', {ipc: true});
83 unmodified lines
modified:test/ipc/get-one.js+2 added-3 removed
8 unmodified lines
9 subprocessSendGetOne,10 subprocessExchange,11 alwaysPass,12} from '../helpers/ipc.js';13import {PARALLEL_COUNT} from '../helpers/parallel.js';1415setFixtureDirectory();1617const testKeepAlive = async (t, buffer, exchangeMethod) => {
62 unmodified lines
8081test('exports.getOneMessage() can filter messages', testFilterSubprocess, 'ipc-echo-filter.js', [foobarArray[1]]);82test('exports.exchangeMessage() can filter messages', testFilterSubprocess, 'ipc-echo-filter-exchange.js', ['.', foobarArray[1]]);8383const HIGH_CONCURRENCY_COUNT = 10;8484const 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 lines
modified:test/ipc/send.js+2 added-3 removed
1 unmodified line
2import {execa} from '../../index.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {foobarString} from '../helpers/input.js';5import {subprocessSendGetOne, subprocessExchange} from '../helpers/ipc.js';6import {PARALLEL_COUNT} from '../helpers/parallel.js';78setFixtureDirectory();910const testExchange = async (t, exchangeMethod) => {
4 unmodified lines
1516test('Can exchange IPC messages', testExchange, subprocessSendGetOne);17test('Can exchange IPC messages, exchangeMessage()', testExchange, subprocessExchange);1818const HIGH_CONCURRENCY_COUNT = 10;1919const 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 lines
modified:test/pipe/streaming.js+3 added-4 removed
4 unmodified lines
5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';6import {foobarString} from '../helpers/input.js';7import {assertMaxListeners} from '../helpers/listeners.js';8import {fullReadableStdio} from '../helpers/stdio.js';9import {PARALLEL_COUNT} from '../helpers/parallel.js';1011setFixtureDirectory();1213test('Can pipe two sources to same destination', async t => {
27 unmodified lines
41 t.is(await secondPipePromise, await destination);42 t.is(await thirdPromise, await destination);43});4444const subprocessesCount = 100;4545test.serial('Can pipe many sources to same destination', async t => {46 const checkMaxListeners = assertMaxListeners(t);4749 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 lines
62test.serial('Can pipe same source to many destinations', async t => {63 const checkMaxListeners = assertMaxListeners(t);6465 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));6970 t.like(await source, {stdout: foobarString});
370 unmodified lines
modified:package.json+1 added
67 unmodified lines
68 "@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