Skip to content
Myr

Cancel generators when the process errors (#783)

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

authored by ehmicky · committed by GitHub · parent 5aa90bd · Browse files · 3 files+57 added−6 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+57 added−6 removed

  • tests:+29 added−1 removed
  • other:+28 added−5 removed

3 files+57 added−6 removed

modified:lib/stdio/transform.js+28 added-5 removed
modified:test/stdio/generator.js+22 added-1 removed
1import {Buffer} from 'node:buffer';2import {once} from 'node:events';3import {readFile, writeFile, rm} from 'node:fs/promises';4import {getDefaultHighWaterMark, PassThrough} from 'node:stream';5import {setTimeout, scheduler} from 'node:timers/promises';6import test from 'ava';
697 unmodified lines
704 childProcess.stdin.write('foobar\n');705 await t.throwsAsync(childProcess, {message: GENERATOR_ERROR_REGEXP});706});707708const testGeneratorCancel = async (t, error) => {709 const childProcess = execa('noop.js', {stdout: infiniteGenerator});710 await once(childProcess.stdout, 'data');711 childProcess.stdout.destroy(error);712 await t.throwsAsync(childProcess);713};714715test('Running generators are canceled on process abort', testGeneratorCancel, undefined);716test('Running generators are canceled on process error', testGeneratorCancel, new Error('test'));717718const testGeneratorDestroy = async (t, transform) => {719 const childProcess = execa('forever.js', {stdout: transform});720 const error = new Error('test');721 childProcess.stdout.destroy(error);722 t.is(await t.throwsAsync(childProcess), error);723};724725test('Generators are destroyed on process error, sync', testGeneratorDestroy, noopGenerator(false));726test('Generators are destroyed on process error, async', testGeneratorDestroy, infiniteGenerator);727707test('Generators are canceled on early process exit', async t => {728test('Generators are destroyed on early process exit', async t => {729 await t.throwsAsync(execa('noop.js', {stdout: infiniteGenerator, uid: -1}));730});
modified:test/stdio/iterable.js+7 added
119 unmodified lines
120};121122test('stdin option can be multiple iterables', testMultipleIterable, 0);123test('stdio[*] option can be multiple iterables', testMultipleIterable, 3);124125test('stdin option iterable is canceled on process error', async t => {126 const iterable = infiniteGenerator();127 await t.throwsAsync(execa('stdin.js', {stdin: iterable, timeout: 1}), {message: /timed out/});128 // eslint-disable-next-line no-unused-vars, no-empty129 for await (const _ of iterable) {}130});