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