Fix randomly failing tests (#793)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 4080212 · Browse files · 3 files·+23 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
3 files+23 added−21 removed
- tests:+23 added−21 removed
Provenance
- Commit
45475e7- Tree
2cc5123- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
4080212
3 files changed+23 added−21 removed
modified:test/stdio/async.js+10 added-9 removed
16 unmodified lines171819202122232425262526272829303127282930313233343527 unmodified lines6364656667686768697071727374757615 unmodified lines16 unmodified lines stdout: ['pipe', 'inherit', ...(isMultiple ? [1, process.stdout] : [])], stderr: ['pipe', 'inherit', ...(isMultiple ? [2, process.stderr] : [])],});
const onStdinRemoveListener = () => once(process.stdin, 'removeListener', {cleanup: true});
const testListenersCleanup = async (t, isMultiple) => { const streamsPreviousListeners = getStandardStreamsListeners(); const childProcess = execa('empty.js', getComplexStdio(isMultiple)); t.notDeepEqual(getStandardStreamsListeners(), streamsPreviousListeners); await Promise.all([ childProcess, once(childProcess.stdin, 'unpipe'), once(process.stdout, 'unpipe'), once(process.stderr, 'unpipe'), ]); await setImmediate(); await childProcess; await onStdinRemoveListener(); if (isMultiple) { await onStdinRemoveListener(); }
for (const [index, streamNewListeners] of Object.entries(getStandardStreamsListeners())) { const defaultListeners = Object.fromEntries(Reflect.ownKeys(streamNewListeners).map(eventName => [eventName, []])); t.deepEqual(streamNewListeners, {...defaultListeners, ...streamsPreviousListeners[index]});27 unmodified lines try { const results = await Promise.all( Array.from({length: processesCount}, () => execa('empty.js', getComplexStdio(isMultiple))), ); await setImmediate(); await setImmediate(); t.true(results.every(({exitCode}) => exitCode === 0)); t.is(warning, undefined); } finally { await setImmediate(); await setImmediate();
for (const standardStream of STANDARD_STREAMS) { t.is(standardStream.getMaxListeners(), maxListenersCount); standardStream.setMaxListeners(defaultMaxListeners); }15 unmodified linesmodified:test/stdio/iterable.js+8 added-6 removed
40 unmodified lines41 test('stdin option can be an iterable of strings', testIterable, stringGenerator(), 0);42 test('stdio[*] option can be an iterable of strings', testIterable, stringGenerator(), 3);43 test('stdin option can be an iterable of Uint8Arrays', testIterable, binaryGenerator(), 0);44 test('stdio[*] option can be an iterable of Uint8Arrays', testIterable, binaryGenerator(), 3);45-test('stdin option can be an async iterable', testIterable, asyncGenerator(), 0);46-test('stdio[*] option can be an async iterable', testIterable, asyncGenerator(), 3);45+test.serial('stdin option can be an async iterable', testIterable, asyncGenerator(), 0);46+test.serial('stdio[*] option can be an async iterable', testIterable, asyncGenerator(), 3);47 48 const foobarObjectGenerator = function * () {49 yield foobarObject;50 };55 unmodified lines106 test('stdout option cannot be an iterable - sync', testNoIterableOutput, stringGenerator(), 1, execaSync);107 test('stderr option cannot be an iterable - sync', testNoIterableOutput, stringGenerator(), 2, execaSync);108 109 test('stdin option can be an infinite iterable', async t => {110- const childProcess = execa('stdin.js', getStdio(0, infiniteGenerator()));111- const stdout = await once(childProcess.stdout, 'data');112- t.true(stdout.toString().startsWith('foo'));110+ const iterable = infiniteGenerator();111+ const childProcess = execa('stdin.js', getStdio(0, iterable));112+ await once(childProcess.stdout, 'data');113 childProcess.kill();114- await t.throwsAsync(childProcess, {code: 'ERR_STREAM_PREMATURE_CLOSE'});114+ const {stdout} = await t.throwsAsync(childProcess);115+ t.true(stdout.startsWith('foo'));116+ t.deepEqual(await iterable.next(), {value: undefined, done: true});117 });118 119 const testMultipleIterable = async (t, index) => {120 const {stdout} = await execa('stdin-fd.js', [`${index}`], getStdio(index, [stringGenerator(), asyncGenerator()]));12 unmodified linesmodified:test/stream.js+5 added-6 removed
1 import {Buffer} from 'node:buffer';2 import {once} from 'node:events';3 import {getDefaultHighWaterMark} from 'node:stream';4-import {setTimeout, setImmediate} from 'node:timers/promises';4+import {setTimeout} from 'node:timers/promises';5 import test from 'ava';6 import getStream from 'get-stream';7 import {execa, execaSync} from '../index.js';8 import {setFixtureDir} from './helpers/fixtures-dir.js';77 unmodified lines86 87 const testLateStream = async (t, index, all) => {88 const subprocess = execa('noop-fd-ipc.js', [`${index}`, foobarString], {...getStdio(4, 'ipc', 4), buffer: false, all});89 await once(subprocess, 'message');90- await setImmediate();90 const [output, allOutput] = await Promise.all([91 getStream(subprocess.stdio[index]),92 all ? getStream(subprocess.all) : undefined,93 subprocess,5 unmodified lines99 t.is(allOutput, '');100 }101 };102 104-test('Lacks some data when stdout is read too late `buffer` set to `false`', testLateStream, 1, false);105-test('Lacks some data when stderr is read too late `buffer` set to `false`', testLateStream, 2, false);106-test('Lacks some data when stdio[*] is read too late `buffer` set to `false`', testLateStream, 3, false);107-test('Lacks some data when all is read too late `buffer` set to `false`', testLateStream, 1, true);103+test.serial('Lacks some data when stdout is read too late `buffer` set to `false`', testLateStream, 1, false);104+test.serial('Lacks some data when stderr is read too late `buffer` set to `false`', testLateStream, 2, false);105+test.serial('Lacks some data when stdio[*] is read too late `buffer` set to `false`', testLateStream, 3, false);106+test.serial('Lacks some data when all is read too late `buffer` set to `false`', testLateStream, 1, true);107 108 // eslint-disable-next-line max-params109 const testIterationBuffer = async (t, index, buffer, useDataEvents, all) => {110 const subprocess = execa('noop-fd.js', [`${index}`, foobarString], {...fullStdio, buffer, all});319 unmodified lines