• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Flags: --experimental-abortcontroller
2'use strict';
3
4const { mustCall } = require('../common');
5const { strictEqual, throws } = require('assert');
6const fixtures = require('../common/fixtures');
7const { spawn } = require('child_process');
8const { getEventListeners } = require('events');
9
10const aliveForeverFile = 'child-process-stay-alive-forever.js';
11{
12  // Verify default signal + closes
13  const cp = spawn(process.execPath, [fixtures.path(aliveForeverFile)], {
14    timeout: 5,
15  });
16  cp.on('exit', mustCall((code, ks) => strictEqual(ks, 'SIGTERM')));
17}
18
19{
20  // Verify SIGKILL signal + closes
21  const cp = spawn(process.execPath, [fixtures.path(aliveForeverFile)], {
22    timeout: 6,
23    killSignal: 'SIGKILL',
24  });
25  cp.on('exit', mustCall((code, ks) => strictEqual(ks, 'SIGKILL')));
26}
27
28{
29  // Verify timeout verification
30  throws(() => spawn(process.execPath, [fixtures.path(aliveForeverFile)], {
31    timeout: 'badValue',
32  }), /ERR_OUT_OF_RANGE/);
33
34  throws(() => spawn(process.execPath, [fixtures.path(aliveForeverFile)], {
35    timeout: {},
36  }), /ERR_OUT_OF_RANGE/);
37}
38
39{
40  // Verify abort signal gets unregistered
41  const controller = new AbortController();
42  const { signal } = controller;
43  const cp = spawn(process.execPath, [fixtures.path(aliveForeverFile)], {
44    timeout: 6,
45    signal,
46  });
47  strictEqual(getEventListeners(signal, 'abort').length, 1);
48  cp.on('exit', mustCall(() => {
49    strictEqual(getEventListeners(signal, 'abort').length, 0);
50  }));
51}
52