Skip to content
Myr

Add race condition-related tests (#618)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by GitHub · parent f1069b0 · Browse files · 3 files+43 added−0 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+43 added−0 removed

  • tests:+43 added−0 removed

3 files+43 added−0 removed

added:test/fixtures/noop-delay.js+6 added
added:test/fixtures/noop-fail.js+5 added
modified:test/stream.js+32 added
2 unmodified lines
3import process from 'node:process';4import fs from 'node:fs';5import {relative} from 'node:path';6import Stream from 'node:stream';7import {setTimeout} from 'node:timers/promises';8import {promisify} from 'node:util';9import {pathToFileURL} from 'node:url';10import test from 'ava';11import getStream from 'get-stream';
484 unmodified lines
496 const childProcess = execa('forever');497 childProcess.stdout.destroy();498 await t.throwsAsync(childProcess, {code: 'ERR_STREAM_PREMATURE_CLOSE'});499});500501test.serial('Processes wait on stdin before exiting', async t => {502 const childProcess = execa('stdin.js');503 await setTimeout(1e3);504 childProcess.stdin.end('foobar');505 const {stdout} = await childProcess;506 t.is(stdout, 'foobar');507});508509test.serial('Processes buffer stdout before it is read', async t => {510 const childProcess = execa('noop-delay.js', ['foobar']);511 await setTimeout(5e2);512 const {stdout} = await childProcess;513 t.is(stdout, 'foobar');514});515516// This test is not the desired behavior, but is the current one.517// I.e. this is mostly meant for documentation and regression testing.518test.serial('Processes might successfully exit before their stdout is read', async t => {519 const childProcess = execa('noop.js', ['foobar']);520 await setTimeout(1e3);521 const {stdout} = await childProcess;522 t.is(stdout, '');523});524525test.serial('Processes might fail before their stdout is read', async t => {526 const childProcess = execa('noop-fail.js', ['foobar'], {reject: false});527 await setTimeout(1e3);528 const {stdout} = await childProcess;529 t.is(stdout, '');530});