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 targos committed Jun 11, 2021
1 parent e5fae63 commit 3215a58
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions test/parallel/test-child-process-spawn-controller.js
Expand Up @@ -5,18 +5,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 3215a58

Please sign in to comment.