2017-06-05 07:35:06 +00:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
2019-09-06 21:25:36 +00:00
|
|
|
const { spawnSync } = require('child_process');
|
2017-06-05 07:35:06 +00:00
|
|
|
const async_hooks = require('async_hooks');
|
|
|
|
const initHooks = require('./init-hooks');
|
|
|
|
|
2017-06-08 20:48:08 +00:00
|
|
|
const arg = process.argv[2];
|
|
|
|
switch (arg) {
|
2017-06-05 07:35:06 +00:00
|
|
|
case 'test_init_callback':
|
|
|
|
initHooks({
|
2022-11-21 17:43:47 +00:00
|
|
|
oninit: common.mustCall(() => { throw new Error(arg); }),
|
2017-06-05 07:35:06 +00:00
|
|
|
}).enable();
|
2017-11-12 17:46:55 +00:00
|
|
|
new async_hooks.AsyncResource(`${arg}_type`);
|
2017-06-08 20:48:08 +00:00
|
|
|
return;
|
2017-06-05 07:35:06 +00:00
|
|
|
|
2022-01-03 04:21:46 +00:00
|
|
|
case 'test_callback': {
|
2017-06-05 07:35:06 +00:00
|
|
|
initHooks({
|
2022-11-21 17:43:47 +00:00
|
|
|
onbefore: common.mustCall(() => { throw new Error(arg); }),
|
2017-06-05 07:35:06 +00:00
|
|
|
}).enable();
|
2017-11-12 17:46:55 +00:00
|
|
|
const resource = new async_hooks.AsyncResource(`${arg}_type`);
|
2019-03-08 15:42:21 +00:00
|
|
|
resource.runInAsyncScope(() => {});
|
2017-06-08 20:48:08 +00:00
|
|
|
return;
|
2022-01-03 04:21:46 +00:00
|
|
|
}
|
2017-06-08 20:48:08 +00:00
|
|
|
|
2017-06-08 19:25:31 +00:00
|
|
|
case 'test_callback_abort':
|
|
|
|
initHooks({
|
2022-11-21 17:43:47 +00:00
|
|
|
oninit: common.mustCall(() => { throw new Error(arg); }),
|
2017-06-08 19:25:31 +00:00
|
|
|
}).enable();
|
2017-11-12 17:46:55 +00:00
|
|
|
new async_hooks.AsyncResource(`${arg}_type`);
|
2017-06-08 20:48:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-10 21:53:44 +00:00
|
|
|
// This part should run only for the primary test
|
2017-06-08 20:48:08 +00:00
|
|
|
assert.ok(!arg);
|
|
|
|
{
|
|
|
|
// console.log should stay until this test's flakiness is solved
|
|
|
|
console.log('start case 1');
|
|
|
|
console.time('end case 1');
|
|
|
|
const child = spawnSync(process.execPath, [__filename, 'test_init_callback']);
|
|
|
|
assert.ifError(child.error);
|
|
|
|
const test_init_first_line = child.stderr.toString().split(/[\r\n]+/g)[0];
|
|
|
|
assert.strictEqual(test_init_first_line, 'Error: test_init_callback');
|
|
|
|
assert.strictEqual(child.status, 1);
|
|
|
|
console.timeEnd('end case 1');
|
|
|
|
}
|
2017-06-05 07:35:06 +00:00
|
|
|
|
2017-06-08 20:48:08 +00:00
|
|
|
{
|
|
|
|
console.log('start case 2');
|
|
|
|
console.time('end case 2');
|
|
|
|
const child = spawnSync(process.execPath, [__filename, 'test_callback']);
|
|
|
|
assert.ifError(child.error);
|
|
|
|
const test_callback_first_line = child.stderr.toString().split(/[\r\n]+/g)[0];
|
|
|
|
assert.strictEqual(test_callback_first_line, 'Error: test_callback');
|
|
|
|
assert.strictEqual(child.status, 1);
|
|
|
|
console.timeEnd('end case 2');
|
2017-06-05 07:35:06 +00:00
|
|
|
}
|
|
|
|
|
2017-06-08 20:48:08 +00:00
|
|
|
{
|
|
|
|
console.log('start case 3');
|
|
|
|
console.time('end case 3');
|
2019-09-06 21:25:36 +00:00
|
|
|
let program = process.execPath;
|
|
|
|
let args = [
|
|
|
|
'--abort-on-uncaught-exception', __filename, 'test_callback_abort' ];
|
2024-09-29 20:44:52 +00:00
|
|
|
let options = {};
|
2019-09-06 21:25:36 +00:00
|
|
|
if (!common.isWindows) {
|
2024-09-29 20:44:52 +00:00
|
|
|
[program, options] = common.escapePOSIXShell`ulimit -c 0 && exec "${program}" ${args[0]} "${args[1]}" ${args[2]}`;
|
2019-09-06 21:25:36 +00:00
|
|
|
args = [];
|
|
|
|
options.shell = true;
|
|
|
|
}
|
2024-09-29 20:44:52 +00:00
|
|
|
|
|
|
|
options.encoding = 'utf8';
|
2019-09-06 21:25:36 +00:00
|
|
|
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') {
|
2020-12-10 21:53:44 +00:00
|
|
|
console.log(`primary received signal ${child.signal}\nchild's stderr:`);
|
2019-09-06 21:25:36 +00:00
|
|
|
console.log(child.stderr);
|
|
|
|
process.exit(1);
|
2017-06-08 20:48:08 +00:00
|
|
|
}
|
2019-09-06 21:25:36 +00:00
|
|
|
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');
|
2017-06-08 20:48:08 +00:00
|
|
|
console.timeEnd('end case 3');
|
|
|
|
}
|