From 909c669c046130eaf8f49978e981a66a61575694 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 6 Sep 2019 23:25:36 +0200 Subject: [PATCH] test: disable core dumps before running crash test The test spawns a subprocess with the `--abort-on-uncaught-exception` flag and expects it to terminate with a SIGABRT signal. On systems where core dumps are enabled, that actually generates an unnecessary core dump. Set `ulimit -c 0` before spawning the subprocess. Fixes: https://github.com/nodejs/node/issues/29286 PR-URL: https://github.com/nodejs/node/pull/29478 Reviewed-By: Colin Ihrig Reviewed-By: David Carlier --- test/async-hooks/test-callback-error.js | 60 +++++++++++-------------- 1 file changed, 26 insertions(+), 34 deletions(-) diff --git a/test/async-hooks/test-callback-error.js b/test/async-hooks/test-callback-error.js index 06d8cb7224ccad..8bbed364980f2b 100644 --- a/test/async-hooks/test-callback-error.js +++ b/test/async-hooks/test-callback-error.js @@ -1,7 +1,7 @@ 'use strict'; const common = require('../common'); const assert = require('assert'); -const { spawnSync, fork } = require('child_process'); +const { spawnSync } = require('child_process'); const async_hooks = require('async_hooks'); const initHooks = require('./init-hooks'); @@ -58,39 +58,31 @@ assert.ok(!arg); { console.log('start case 3'); console.time('end case 3'); - const opts = { - execArgv: ['--abort-on-uncaught-exception'], - silent: true - }; - const child = fork(__filename, ['test_callback_abort'], opts); - - let stdout = ''; - child.stdout.on('data', (data) => { - stdout += data; - }); - - let stderr = ''; - child.stderr.on('data', (data) => { - stderr += data; - }); - - child.on('close', (code, signal) => { - if (common.isWindows) { - assert.strictEqual(code, 134); - assert.strictEqual(signal, null); - } else { - assert.strictEqual(code, null); - // Most posix systems will show 'SIGABRT', but alpine34 does not - if (signal !== 'SIGABRT') { - console.log(`parent received signal ${signal}\nchild's stderr:`); - console.log(stderr); - process.exit(1); - } - assert.strictEqual(signal, 'SIGABRT'); + let program = process.execPath; + let args = [ + '--abort-on-uncaught-exception', __filename, 'test_callback_abort' ]; + const options = { encoding: 'utf8' }; + if (!common.isWindows) { + program = `ulimit -c 0 && exec ${program} ${args.join(' ')}`; + args = []; + options.shell = true; + } + const child = spawnSync(program, args, options); + if (common.isWindows) { + assert.strictEqual(child.status, 134); + assert.strictEqual(child.signal, null); + } else { + assert.strictEqual(child.status, null); + // Most posix systems will show 'SIGABRT', but alpine34 does not + if (child.signal !== 'SIGABRT') { + console.log(`parent received signal ${child.signal}\nchild's stderr:`); + console.log(child.stderr); + process.exit(1); } - assert.strictEqual(stdout, ''); - const firstLineStderr = stderr.split(/[\r\n]+/g)[0].trim(); - assert.strictEqual(firstLineStderr, 'Error: test_callback_abort'); - }); + assert.strictEqual(child.signal, 'SIGABRT'); + } + assert.strictEqual(child.stdout, ''); + const firstLineStderr = child.stderr.split(/[\r\n]+/g)[0].trim(); + assert.strictEqual(firstLineStderr, 'Error: test_callback_abort'); console.timeEnd('end case 3'); }