11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst async_hooks = require('async_hooks');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciif (!common.isMainThread)
71cb0ef41Sopenharmony_ci  common.skip('Worker bootstrapping works differently -> different async IDs');
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconst promiseAsyncIds = [];
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciasync_hooks.createHook({
121cb0ef41Sopenharmony_ci  init: common.mustCallAtLeast((id, type, triggerId) => {
131cb0ef41Sopenharmony_ci    if (type === 'PROMISE') {
141cb0ef41Sopenharmony_ci      // Check that the last known Promise is triggering the creation of
151cb0ef41Sopenharmony_ci      // this one.
161cb0ef41Sopenharmony_ci      assert.strictEqual(triggerId,
171cb0ef41Sopenharmony_ci                         promiseAsyncIds[promiseAsyncIds.length - 1] || 1);
181cb0ef41Sopenharmony_ci      promiseAsyncIds.push(id);
191cb0ef41Sopenharmony_ci    }
201cb0ef41Sopenharmony_ci  }, 3),
211cb0ef41Sopenharmony_ci  before: common.mustCall((id) => {
221cb0ef41Sopenharmony_ci    assert.strictEqual(id, promiseAsyncIds[1]);
231cb0ef41Sopenharmony_ci  }),
241cb0ef41Sopenharmony_ci  after: common.mustCall((id) => {
251cb0ef41Sopenharmony_ci    assert.strictEqual(id, promiseAsyncIds[1]);
261cb0ef41Sopenharmony_ci  })
271cb0ef41Sopenharmony_ci}).enable();
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ciPromise.resolve(42).then(common.mustCall(() => {
301cb0ef41Sopenharmony_ci  assert.strictEqual(async_hooks.executionAsyncId(), promiseAsyncIds[1]);
311cb0ef41Sopenharmony_ci  assert.strictEqual(async_hooks.triggerAsyncId(), promiseAsyncIds[0]);
321cb0ef41Sopenharmony_ci  Promise.resolve(10);
331cb0ef41Sopenharmony_ci}));
34