11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci// Flags: --expose-internals 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ciconst cp = require('child_process'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciif (process.argv[2] === 'child') { 81cb0ef41Sopenharmony_ci // Since maxBuffer is 0, this should trigger an error. 91cb0ef41Sopenharmony_ci console.log('foo'); 101cb0ef41Sopenharmony_ci} else { 111cb0ef41Sopenharmony_ci const internalCp = require('internal/child_process'); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci // Monkey patch ChildProcess#kill() to kill the process and then throw. 141cb0ef41Sopenharmony_ci const kill = internalCp.ChildProcess.prototype.kill; 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci internalCp.ChildProcess.prototype.kill = function() { 171cb0ef41Sopenharmony_ci kill.apply(this, arguments); 181cb0ef41Sopenharmony_ci throw new Error('mock error'); 191cb0ef41Sopenharmony_ci }; 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci const cmd = `"${process.execPath}" "${__filename}" child`; 221cb0ef41Sopenharmony_ci const options = { maxBuffer: 0, killSignal: 'SIGKILL' }; 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci const child = cp.exec(cmd, options, common.mustCall((err, stdout, stderr) => { 251cb0ef41Sopenharmony_ci // Verify that if ChildProcess#kill() throws, the error is reported. 261cb0ef41Sopenharmony_ci assert.strictEqual(err.message, 'mock error', err); 271cb0ef41Sopenharmony_ci assert.strictEqual(stdout, ''); 281cb0ef41Sopenharmony_ci assert.strictEqual(stderr, ''); 291cb0ef41Sopenharmony_ci assert.strictEqual(child.killed, true); 301cb0ef41Sopenharmony_ci })); 311cb0ef41Sopenharmony_ci} 32