diff --git a/package.json b/package.json index 8ed7e30cc2..1a617286f7 100644 --- a/package.json +++ b/package.json @@ -69,6 +69,7 @@ "ava": "^6.0.1", "c8": "^9.1.0", "get-node": "^15.0.0", + "is-in-ci": "^0.1.0", "is-running": "^2.1.0", "path-exists": "^5.0.0", "path-key": "^4.0.0", diff --git a/test/helpers/parallel.js b/test/helpers/parallel.js new file mode 100644 index 0000000000..3f96acafc3 --- /dev/null +++ b/test/helpers/parallel.js @@ -0,0 +1,3 @@ +import isInCi from 'is-in-ci'; + +export const PARALLEL_COUNT = isInCi ? 10 : 100; diff --git a/test/io/output-async.js b/test/io/output-async.js index 8ab44a555f..081948418b 100644 --- a/test/io/output-async.js +++ b/test/io/output-async.js @@ -7,6 +7,7 @@ import {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(); @@ -39,11 +40,9 @@ const testListenersCleanup = async (t, isMultiple) => { 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)); }); @@ -57,7 +56,7 @@ const testMaxListeners = async (t, isMultiple, maxListenersCount) => { 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 { diff --git a/test/ipc/buffer-messages.js b/test/ipc/buffer-messages.js index 730220d00e..a14d3d2abf 100644 --- a/test/ipc/buffer-messages.js +++ b/test/ipc/buffer-messages.js @@ -2,6 +2,7 @@ import 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(); @@ -57,11 +58,9 @@ test('Sets empty error.ipcOutput, sync', t => { 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}`]); }), diff --git a/test/ipc/get-each.js b/test/ipc/get-each.js index b8284b9381..394c3e6cac 100644 --- a/test/ipc/get-each.js +++ b/test/ipc/get-each.js @@ -3,6 +3,7 @@ import {execa} from '../../index.js'; import {setFixtureDirectory} from '../helpers/fixtures-directory.js'; import {foobarString, foobarArray} from '../helpers/input.js'; import {iterateAllMessages} from '../helpers/ipc.js'; +import {PARALLEL_COUNT} from '../helpers/parallel.js'; setFixtureDirectory(); @@ -82,15 +83,13 @@ test('Exceptions in subprocess.getEachMessage() disconnect', async t => { t.deepEqual(ipcOutput, [foobarString]); }); -const HIGH_CONCURRENCY_COUNT = 10; - test.serial('Can send many messages at once with exports.getEachMessage()', async t => { const subprocess = execa('ipc-iterate.js', {ipc: true}); - await Promise.all(Array.from({length: HIGH_CONCURRENCY_COUNT}, (_, index) => subprocess.sendMessage(index))); + await Promise.all(Array.from({length: PARALLEL_COUNT}, (_, index) => subprocess.sendMessage(index))); await subprocess.sendMessage(foobarString); const {ipcOutput} = await subprocess; - t.deepEqual(ipcOutput, Array.from({length: HIGH_CONCURRENCY_COUNT}, (_, index) => index)); + t.deepEqual(ipcOutput, Array.from({length: PARALLEL_COUNT}, (_, index) => index)); }); test('Disconnecting in the current process stops exports.getEachMessage()', async t => { diff --git a/test/ipc/get-one.js b/test/ipc/get-one.js index 2e2c30e178..97c2abc0b7 100644 --- a/test/ipc/get-one.js +++ b/test/ipc/get-one.js @@ -10,6 +10,7 @@ import { subprocessExchange, alwaysPass, } from '../helpers/ipc.js'; +import {PARALLEL_COUNT} from '../helpers/parallel.js'; setFixtureDirectory(); @@ -80,11 +81,9 @@ const testFilterSubprocess = async (t, fixtureName, expectedOutput) => { test('exports.getOneMessage() can filter messages', testFilterSubprocess, 'ipc-echo-filter.js', [foobarArray[1]]); test('exports.exchangeMessage() can filter messages', testFilterSubprocess, 'ipc-echo-filter-exchange.js', ['.', foobarArray[1]]); -const HIGH_CONCURRENCY_COUNT = 10; - const testHeavyLoad = async (t, exchangeMethod) => { await Promise.all( - Array.from({length: HIGH_CONCURRENCY_COUNT}, async (_, index) => { + Array.from({length: PARALLEL_COUNT}, async (_, index) => { const subprocess = execa('ipc-send-argv.js', [`${index}`], {ipc: true, buffer: false}); t.is(await exchangeMethod(subprocess, {}), `${index}`); await subprocess; diff --git a/test/ipc/send.js b/test/ipc/send.js index 981ac293e5..89af8f685b 100644 --- a/test/ipc/send.js +++ b/test/ipc/send.js @@ -3,6 +3,7 @@ import {execa} from '../../index.js'; import {setFixtureDirectory} from '../helpers/fixtures-directory.js'; import {foobarString} from '../helpers/input.js'; import {subprocessSendGetOne, subprocessExchange} from '../helpers/ipc.js'; +import {PARALLEL_COUNT} from '../helpers/parallel.js'; setFixtureDirectory(); @@ -15,11 +16,9 @@ const testExchange = async (t, exchangeMethod) => { test('Can exchange IPC messages', testExchange, subprocessSendGetOne); test('Can exchange IPC messages, exchangeMessage()', testExchange, subprocessExchange); -const HIGH_CONCURRENCY_COUNT = 10; - const testHeavyLoad = async (t, exchangeMethod) => { await Promise.all( - Array.from({length: HIGH_CONCURRENCY_COUNT}, async (_, index) => { + Array.from({length: PARALLEL_COUNT}, async (_, index) => { const subprocess = execa('ipc-echo.js', {ipc: true}); t.is(await exchangeMethod(subprocess, index), index); await subprocess; diff --git a/test/pipe/streaming.js b/test/pipe/streaming.js index ebdc18a8cd..bd92202a90 100644 --- a/test/pipe/streaming.js +++ b/test/pipe/streaming.js @@ -6,6 +6,7 @@ import {setFixtureDirectory} from '../helpers/fixtures-directory.js'; import {foobarString} from '../helpers/input.js'; import {assertMaxListeners} from '../helpers/listeners.js'; import {fullReadableStdio} from '../helpers/stdio.js'; +import {PARALLEL_COUNT} from '../helpers/parallel.js'; setFixtureDirectory(); @@ -41,12 +42,10 @@ test('Can pipe three sources to same destination', async t => { t.is(await thirdPromise, await destination); }); -const subprocessesCount = 100; - test.serial('Can pipe many sources to same destination', async t => { const checkMaxListeners = assertMaxListeners(t); - const expectedResults = Array.from({length: subprocessesCount}, (_, index) => `${index}`).sort(); + const expectedResults = Array.from({length: PARALLEL_COUNT}, (_, index) => `${index}`).sort(); const sources = expectedResults.map(expectedResult => execa('noop.js', [expectedResult])); const destination = execa('stdin.js'); const pipePromises = sources.map(source => source.pipe(destination)); @@ -64,7 +63,7 @@ test.serial('Can pipe same source to many destinations', async t => { const checkMaxListeners = assertMaxListeners(t); const source = execa('noop-fd.js', ['1', foobarString]); - const expectedResults = Array.from({length: subprocessesCount}, (_, index) => `${index}`); + const expectedResults = Array.from({length: PARALLEL_COUNT}, (_, index) => `${index}`); const destinations = expectedResults.map(expectedResult => execa('noop-stdin-double.js', [expectedResult])); const pipePromises = destinations.map(destination => source.pipe(destination));