2017-06-09 21:27:02 +02:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const async_hooks = require('async_hooks');
|
2025-01-22 14:19:38 -08:00
|
|
|
const { isMainThread } = require('worker_threads');
|
2017-06-09 21:27:02 +02:00
|
|
|
|
2025-01-22 14:19:38 -08:00
|
|
|
if (!isMainThread) {
|
2018-05-18 01:20:25 +02:00
|
|
|
common.skip('Worker bootstrapping works differently -> different async IDs');
|
2025-01-22 14:19:38 -08:00
|
|
|
}
|
2018-05-18 01:20:25 +02:00
|
|
|
|
2017-06-09 21:27:02 +02:00
|
|
|
const promiseAsyncIds = [];
|
|
|
|
|
|
|
|
async_hooks.createHook({
|
|
|
|
init: common.mustCallAtLeast((id, type, triggerId) => {
|
|
|
|
if (type === 'PROMISE') {
|
|
|
|
// Check that the last known Promise is triggering the creation of
|
|
|
|
// this one.
|
2019-11-20 22:42:47 +01:00
|
|
|
assert.strictEqual(triggerId,
|
|
|
|
promiseAsyncIds[promiseAsyncIds.length - 1] || 1);
|
2017-06-09 21:27:02 +02:00
|
|
|
promiseAsyncIds.push(id);
|
|
|
|
}
|
|
|
|
}, 3),
|
|
|
|
before: common.mustCall((id) => {
|
|
|
|
assert.strictEqual(id, promiseAsyncIds[1]);
|
|
|
|
}),
|
|
|
|
after: common.mustCall((id) => {
|
|
|
|
assert.strictEqual(id, promiseAsyncIds[1]);
|
|
|
|
})
|
|
|
|
}).enable();
|
|
|
|
|
|
|
|
Promise.resolve(42).then(common.mustCall(() => {
|
|
|
|
assert.strictEqual(async_hooks.executionAsyncId(), promiseAsyncIds[1]);
|
|
|
|
assert.strictEqual(async_hooks.triggerAsyncId(), promiseAsyncIds[0]);
|
|
|
|
Promise.resolve(10);
|
|
|
|
}));
|