Skip to content

Commit

Permalink
test: disable core dumps before running crash test
Browse files Browse the repository at this point in the history
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: #29286

PR-URL: #29478
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
  • Loading branch information
bnoordhuis authored and BridgeAR committed Sep 25, 2019
1 parent 9e63f91 commit 909c669
Showing 1 changed file with 26 additions and 34 deletions.
60 changes: 26 additions & 34 deletions test/async-hooks/test-callback-error.js
Original file line number Diff line number Diff line change
@@ -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');

Expand Down Expand Up @@ -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');
}

0 comments on commit 909c669

Please sign in to comment.