Skip to content

Commit f0dfe57

Browse files
Trottdanielleadams
authored andcommitted
test: add already-aborted-controller test for spawn()
PR-URL: #36644 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Daijiro Wachi <[email protected]>
1 parent b98cc51 commit f0dfe57

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

test/parallel/test-child-process-spawn-controller.js

+32-12
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,38 @@ const common = require('../common');
44
const assert = require('assert');
55
const cp = require('child_process');
66

7-
// Verify that passing an AbortSignal works
8-
const controller = new AbortController();
9-
const { signal } = controller;
7+
{
8+
// Verify that passing an AbortSignal works
9+
const controller = new AbortController();
10+
const { signal } = controller;
1011

11-
const echo = cp.spawn('echo', ['fun'], {
12-
encoding: 'utf8',
13-
shell: true,
14-
signal
15-
});
12+
const echo = cp.spawn('echo', ['fun'], {
13+
encoding: 'utf8',
14+
shell: true,
15+
signal
16+
});
1617

17-
echo.on('error', common.mustCall((e) => {
18-
assert.strictEqual(e.name, 'AbortError');
19-
}));
18+
echo.on('error', common.mustCall((e) => {
19+
assert.strictEqual(e.name, 'AbortError');
20+
}));
2021

21-
controller.abort();
22+
controller.abort();
23+
}
24+
25+
{
26+
// Verify that passing an already-aborted signal works.
27+
const controller = new AbortController();
28+
const { signal } = controller;
29+
30+
controller.abort();
31+
32+
const echo = cp.spawn('echo', ['fun'], {
33+
encoding: 'utf8',
34+
shell: true,
35+
signal
36+
});
37+
38+
echo.on('error', common.mustCall((e) => {
39+
assert.strictEqual(e.name, 'AbortError');
40+
}));
41+
}

0 commit comments

Comments
 (0)