2017-06-04 11:35:56 +00:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const async_hooks = require('async_hooks');
|
|
|
|
|
2018-05-17 23:20:25 +00:00
|
|
|
if (!common.isMainThread)
|
|
|
|
common.skip('Worker bootstrapping works differently -> different async IDs');
|
|
|
|
|
2017-06-04 11:35:56 +00:00
|
|
|
const initCalls = [];
|
2017-09-09 15:50:42 +00:00
|
|
|
const resolveCalls = [];
|
2017-06-04 11:35:56 +00:00
|
|
|
|
|
|
|
async_hooks.createHook({
|
|
|
|
init: common.mustCall((id, type, triggerId, resource) => {
|
|
|
|
assert.strictEqual(type, 'PROMISE');
|
2017-07-11 00:55:21 +00:00
|
|
|
initCalls.push({ id, triggerId, resource });
|
2017-09-09 15:50:42 +00:00
|
|
|
}, 2),
|
|
|
|
promiseResolve: common.mustCall((id) => {
|
|
|
|
assert.strictEqual(initCalls[resolveCalls.length].id, id);
|
|
|
|
resolveCalls.push(id);
|
2017-06-04 11:35:56 +00:00
|
|
|
}, 2)
|
|
|
|
}).enable();
|
|
|
|
|
|
|
|
const a = Promise.resolve(42);
|
2018-10-12 06:56:26 +00:00
|
|
|
a.then(common.mustCall());
|
2017-06-04 11:35:56 +00:00
|
|
|
|
|
|
|
assert.strictEqual(initCalls[0].triggerId, 1);
|
|
|
|
assert.strictEqual(initCalls[1].triggerId, initCalls[0].id);
|