1'use strict'; 2 3// Test exec() with a timeout that expires. 4 5const common = require('../common'); 6const assert = require('assert'); 7const cp = require('child_process'); 8 9const { 10 cleanupStaleProcess, 11 logAfterTime, 12 kExpiringChildRunTime, 13 kExpiringParentTimer 14} = require('../common/child_process'); 15 16if (process.argv[2] === 'child') { 17 logAfterTime(kExpiringChildRunTime); 18 return; 19} 20 21const cmd = `"${process.execPath}" "${__filename}" child`; 22 23cp.exec(cmd, { 24 timeout: kExpiringParentTimer, 25}, common.mustCall((err, stdout, stderr) => { 26 console.log('[stdout]', stdout.trim()); 27 console.log('[stderr]', stderr.trim()); 28 29 let sigterm = 'SIGTERM'; 30 assert.strictEqual(err.killed, true); 31 // TODO OpenBSD returns a null signal and 143 for code 32 if (common.isOpenBSD) { 33 assert.strictEqual(err.code, 143); 34 sigterm = null; 35 } else { 36 assert.strictEqual(err.code, null); 37 } 38 // At least starting with Darwin Kernel Version 16.4.0, sending a SIGTERM to a 39 // process that is still starting up kills it with SIGKILL instead of SIGTERM. 40 // See: https://github.com/libuv/libuv/issues/1226 41 if (common.isOSX) 42 assert.ok(err.signal === 'SIGTERM' || err.signal === 'SIGKILL'); 43 else 44 assert.strictEqual(err.signal, sigterm); 45 assert.strictEqual(err.cmd, cmd); 46 assert.strictEqual(stdout.trim(), ''); 47 assert.strictEqual(stderr.trim(), ''); 48})); 49 50cleanupStaleProcess(__filename); 51