mirror of
https://github.com/nodejs/node.git
synced 2025-04-30 23:56:58 +00:00

AsyncResource.emitBefore and AsyncResource.emitAfter have been deprecated in https://github.com/nodejs/node/pull/18632. This PR removes it all. This commit also updates some embedder tests to use internal APIs. The conditions are still possible for Node.js core developers but not for end users. PR-URL: https://github.com/nodejs/node/pull/26530 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com> Reviewed-By: Benedikt Meurer <benedikt.meurer@gmail.com> Reviewed-By: Yang Guo <yangguo@chromium.org> Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
97 lines
2.8 KiB
JavaScript
97 lines
2.8 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const { spawnSync, fork } = require('child_process');
|
|
const async_hooks = require('async_hooks');
|
|
const initHooks = require('./init-hooks');
|
|
|
|
const arg = process.argv[2];
|
|
switch (arg) {
|
|
case 'test_init_callback':
|
|
initHooks({
|
|
oninit: common.mustCall(() => { throw new Error(arg); })
|
|
}).enable();
|
|
new async_hooks.AsyncResource(`${arg}_type`);
|
|
return;
|
|
|
|
case 'test_callback':
|
|
initHooks({
|
|
onbefore: common.mustCall(() => { throw new Error(arg); })
|
|
}).enable();
|
|
const resource = new async_hooks.AsyncResource(`${arg}_type`);
|
|
resource.runInAsyncScope(() => {});
|
|
return;
|
|
|
|
case 'test_callback_abort':
|
|
initHooks({
|
|
oninit: common.mustCall(() => { throw new Error(arg); })
|
|
}).enable();
|
|
new async_hooks.AsyncResource(`${arg}_type`);
|
|
return;
|
|
}
|
|
|
|
// This part should run only for the master test
|
|
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');
|
|
}
|
|
|
|
{
|
|
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');
|
|
}
|
|
|
|
{
|
|
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');
|
|
}
|
|
assert.strictEqual(stdout, '');
|
|
const firstLineStderr = stderr.split(/[\r\n]+/g)[0].trim();
|
|
assert.strictEqual(firstLineStderr, 'Error: test_callback_abort');
|
|
});
|
|
console.timeEnd('end case 3');
|
|
}
|