Skip to content

Commit 3215a58

Browse files
Trotttargos
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 e5fae63 commit 3215a58

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
@@ -5,18 +5,38 @@ const common = require('../common');
55
const assert = require('assert');
66
const cp = require('child_process');
77

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

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

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

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

0 commit comments

Comments
 (0)