1'use strict'; 2 3const { mustCall } = require('../common'); 4const { strictEqual, throws } = require('assert'); 5const fixtures = require('../common/fixtures'); 6const { fork } = require('child_process'); 7const { getEventListeners } = require('events'); 8 9{ 10 // Verify default signal 11 const cp = fork(fixtures.path('child-process-stay-alive-forever.js'), { 12 timeout: 5, 13 }); 14 cp.on('exit', mustCall((code, ks) => strictEqual(ks, 'SIGTERM'))); 15} 16 17{ 18 // Verify correct signal + closes after at least 4 ms. 19 const cp = fork(fixtures.path('child-process-stay-alive-forever.js'), { 20 timeout: 5, 21 killSignal: 'SIGKILL', 22 }); 23 cp.on('exit', mustCall((code, ks) => strictEqual(ks, 'SIGKILL'))); 24} 25 26{ 27 // Verify timeout verification 28 throws(() => fork(fixtures.path('child-process-stay-alive-forever.js'), { 29 timeout: 'badValue', 30 }), /ERR_OUT_OF_RANGE/); 31 32 throws(() => fork(fixtures.path('child-process-stay-alive-forever.js'), { 33 timeout: {}, 34 }), /ERR_OUT_OF_RANGE/); 35} 36 37{ 38 // Verify abort signal gets unregistered 39 const signal = new EventTarget(); 40 signal.aborted = false; 41 42 const cp = fork(fixtures.path('child-process-stay-alive-forever.js'), { 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