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 { fork } = require('child_process');
71cb0ef41Sopenharmony_ciconst { getEventListeners } = require('events');
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci{
101cb0ef41Sopenharmony_ci  // Verify default signal
111cb0ef41Sopenharmony_ci  const cp = fork(fixtures.path('child-process-stay-alive-forever.js'), {
121cb0ef41Sopenharmony_ci    timeout: 5,
131cb0ef41Sopenharmony_ci  });
141cb0ef41Sopenharmony_ci  cp.on('exit', mustCall((code, ks) => strictEqual(ks, 'SIGTERM')));
151cb0ef41Sopenharmony_ci}
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci{
181cb0ef41Sopenharmony_ci  // Verify correct signal + closes after at least 4 ms.
191cb0ef41Sopenharmony_ci  const cp = fork(fixtures.path('child-process-stay-alive-forever.js'), {
201cb0ef41Sopenharmony_ci    timeout: 5,
211cb0ef41Sopenharmony_ci    killSignal: 'SIGKILL',
221cb0ef41Sopenharmony_ci  });
231cb0ef41Sopenharmony_ci  cp.on('exit', mustCall((code, ks) => strictEqual(ks, 'SIGKILL')));
241cb0ef41Sopenharmony_ci}
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci{
271cb0ef41Sopenharmony_ci  // Verify timeout verification
281cb0ef41Sopenharmony_ci  throws(() => fork(fixtures.path('child-process-stay-alive-forever.js'), {
291cb0ef41Sopenharmony_ci    timeout: 'badValue',
301cb0ef41Sopenharmony_ci  }), /ERR_OUT_OF_RANGE/);
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci  throws(() => fork(fixtures.path('child-process-stay-alive-forever.js'), {
331cb0ef41Sopenharmony_ci    timeout: {},
341cb0ef41Sopenharmony_ci  }), /ERR_OUT_OF_RANGE/);
351cb0ef41Sopenharmony_ci}
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ci{
381cb0ef41Sopenharmony_ci  // Verify abort signal gets unregistered
391cb0ef41Sopenharmony_ci  const signal = new EventTarget();
401cb0ef41Sopenharmony_ci  signal.aborted = false;
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ci  const cp = fork(fixtures.path('child-process-stay-alive-forever.js'), {
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