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