11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst { mustCall } = require('../common'); 41cb0ef41Sopenharmony_ciconst { strictEqual, throws } = require('assert'); 51cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures'); 61cb0ef41Sopenharmony_ciconst { spawn } = require('child_process'); 71cb0ef41Sopenharmony_ciconst { getEventListeners } = require('events'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciconst aliveForeverFile = 'child-process-stay-alive-forever.js'; 101cb0ef41Sopenharmony_ci{ 111cb0ef41Sopenharmony_ci // Verify default signal + closes 121cb0ef41Sopenharmony_ci const cp = spawn(process.execPath, [fixtures.path(aliveForeverFile)], { 131cb0ef41Sopenharmony_ci timeout: 5, 141cb0ef41Sopenharmony_ci }); 151cb0ef41Sopenharmony_ci cp.on('exit', mustCall((code, ks) => strictEqual(ks, 'SIGTERM'))); 161cb0ef41Sopenharmony_ci} 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci{ 191cb0ef41Sopenharmony_ci // Verify SIGKILL signal + closes 201cb0ef41Sopenharmony_ci const cp = spawn(process.execPath, [fixtures.path(aliveForeverFile)], { 211cb0ef41Sopenharmony_ci timeout: 6, 221cb0ef41Sopenharmony_ci killSignal: 'SIGKILL', 231cb0ef41Sopenharmony_ci }); 241cb0ef41Sopenharmony_ci cp.on('exit', mustCall((code, ks) => strictEqual(ks, 'SIGKILL'))); 251cb0ef41Sopenharmony_ci} 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci{ 281cb0ef41Sopenharmony_ci // Verify timeout verification 291cb0ef41Sopenharmony_ci throws(() => spawn(process.execPath, [fixtures.path(aliveForeverFile)], { 301cb0ef41Sopenharmony_ci timeout: 'badValue', 311cb0ef41Sopenharmony_ci }), /ERR_OUT_OF_RANGE/); 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ci throws(() => spawn(process.execPath, [fixtures.path(aliveForeverFile)], { 341cb0ef41Sopenharmony_ci timeout: {}, 351cb0ef41Sopenharmony_ci }), /ERR_OUT_OF_RANGE/); 361cb0ef41Sopenharmony_ci} 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ci{ 391cb0ef41Sopenharmony_ci // Verify abort signal gets unregistered 401cb0ef41Sopenharmony_ci const controller = new AbortController(); 411cb0ef41Sopenharmony_ci const { signal } = controller; 421cb0ef41Sopenharmony_ci const cp = spawn(process.execPath, [fixtures.path(aliveForeverFile)], { 431cb0ef41Sopenharmony_ci timeout: 6, 441cb0ef41Sopenharmony_ci signal, 451cb0ef41Sopenharmony_ci }); 461cb0ef41Sopenharmony_ci strictEqual(getEventListeners(signal, 'abort').length, 1); 471cb0ef41Sopenharmony_ci cp.on('exit', mustCall(() => { 481cb0ef41Sopenharmony_ci strictEqual(getEventListeners(signal, 'abort').length, 0); 491cb0ef41Sopenharmony_ci })); 501cb0ef41Sopenharmony_ci} 51