Skip to content

Commit

Permalink
test: add already-aborted-controller test for spawn()
Browse files Browse the repository at this point in the history
PR-URL: #36644
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
  • Loading branch information
Trott authored and danielleadams committed Jan 12, 2021
1 parent b98cc51 commit f0dfe57
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions test/parallel/test-child-process-spawn-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,38 @@ const common = require('../common');
const assert = require('assert');
const cp = require('child_process');

// Verify that passing an AbortSignal works
const controller = new AbortController();
const { signal } = controller;
{
// Verify that passing an AbortSignal works
const controller = new AbortController();
const { signal } = controller;

const echo = cp.spawn('echo', ['fun'], {
encoding: 'utf8',
shell: true,
signal
});
const echo = cp.spawn('echo', ['fun'], {
encoding: 'utf8',
shell: true,
signal
});

echo.on('error', common.mustCall((e) => {
assert.strictEqual(e.name, 'AbortError');
}));
echo.on('error', common.mustCall((e) => {
assert.strictEqual(e.name, 'AbortError');
}));

controller.abort();
controller.abort();
}

{
// Verify that passing an already-aborted signal works.
const controller = new AbortController();
const { signal } = controller;

controller.abort();

const echo = cp.spawn('echo', ['fun'], {
encoding: 'utf8',
shell: true,
signal
});

echo.on('error', common.mustCall((e) => {
assert.strictEqual(e.name, 'AbortError');
}));
}

0 comments on commit f0dfe57

Please sign in to comment.