Fix randomly failing tests (#672)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 90e0e13 · Browse files · 1 file·+25 added−19 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+25 added−19 removed
- tests:+25 added−19 removed
Provenance
- Commit
282d189- Tree
8d6b058- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
90e0e13
1 file changed+25 added−19 removed
modified:test/stream.js+25 added-19 removed
176 unmodified lines177 const subprocess = execa('wrong command', {buffer: false, reject: false});178 await t.notThrowsAsync(Promise.all([subprocess, pEvent(subprocess.stdout, 'end')]));179 });180 181-const BUFFER_TIMEOUT = 1e3;182-183-// On Unix (not Windows), a process won't exit if stdout has not been read.184-if (process.platform !== 'win32') {185- test.serial('buffer: false > promise does not resolve when output is big and is not read', async t => {186- const {timedOut} = await t.throwsAsync(execa('max-buffer.js', {buffer: false, timeout: BUFFER_TIMEOUT}));181+// This specific behavior does not happen on Windows.182+// Also, on macOS, it randomly happens, which would make those tests randomly fail.183+if (process.platform === 'linux') {184+ const testBufferNotRead = async (t, streamArgument, all) => {185+ const {timedOut} = await t.throwsAsync(execa('max-buffer.js', [streamArgument], {buffer: false, all, timeout: 1e3}));186 t.true(timedOut);188- });187+ };188 190- test.serial('buffer: false > promise does not resolve when output is big and "all" is used but not read', async t => {191- const subprocess = execa('max-buffer.js', {buffer: false, all: true, timeout: BUFFER_TIMEOUT});192- subprocess.stdout.resume();193- subprocess.stderr.resume();194- const {timedOut} = await t.throwsAsync(subprocess);195- t.true(timedOut);196- });189+ test.serial('Process buffers stdout, which prevents exit if not read and buffer is false', testBufferNotRead, 'stdout', false);190+ test.serial('Process buffers stderr, which prevents exit if not read and buffer is false', testBufferNotRead, 'stderr', false);191+ test.serial('Process buffers all, which prevents exit if not read and buffer is false', testBufferNotRead, 'stdout', true);192+193+ const testBufferRead = async (t, streamName, streamArgument, all) => {194+ const subprocess = execa('max-buffer.js', [streamArgument], {buffer: false, all, timeout: 1e4});195+ subprocess[streamName].resume();196+ const {timedOut} = await subprocess;197+ t.false(timedOut);198+ };199+200+ test.serial('Process buffers stdout, which does not prevent exit if read and buffer is false', testBufferRead, 'stdout', 'stdout', false);201+ test.serial('Process buffers stderr, which does not prevent exit if read and buffer is false', testBufferRead, 'stderr', 'stderr', false);202+ test.serial('Process buffers all, which does not prevent exit if read and buffer is false', testBufferRead, 'all', 'stdout', true);203 }204 205 test('Errors on streams should make the process exit', async t => {206 const childProcess = execa('forever.js');207 childProcess.stdout.destroy();208 await t.throwsAsync(childProcess, {code: 'ERR_STREAM_PREMATURE_CLOSE'});209 });210 205-test.serial('Processes wait on stdin before exiting', async t => {211+test.serial('Process waits on stdin before exiting', async t => {212 const childProcess = execa('stdin.js');213 await setTimeout(1e3);214 childProcess.stdin.end('foobar');215 const {stdout} = await childProcess;216 t.is(stdout, 'foobar');217 });218 213-test.serial('Processes buffer stdout before it is read', async t => {219+test.serial('Process buffers stdout before it is read', async t => {220 const childProcess = execa('noop-delay.js', ['foobar']);221 await setTimeout(5e2);222 const {stdout} = await childProcess;223 t.is(stdout, 'foobar');224 });225 220-test.serial('Processes buffers stdout right away, on successfully exit', async t => {226+test.serial('Process buffers stdout right away, on successfully exit', async t => {227 const childProcess = execa('noop.js', ['foobar']);228 await setTimeout(1e3);229 const {stdout} = await childProcess;230 t.is(stdout, 'foobar');231 });232 227-test.serial('Processes buffers stdout right away, on failure', async t => {233+test.serial('Process buffers stdout right away, on failure', async t => {234 const childProcess = execa('noop-fail.js', ['foobar'], {reject: false});235 await setTimeout(1e3);236 const {stdout} = await childProcess;237 t.is(stdout, 'foobar');238 });239 234-test('Processes buffers stdout right away, even if directly read', async t => {240+test('Process buffers stdout right away, even if directly read', async t => {241 const childProcess = execa('noop.js', ['foobar']);242 const data = await once(childProcess.stdout, 'data');243 t.is(data.toString().trim(), 'foobar');244 const {stdout} = await childProcess;9 unmodified lines