11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst async_hooks = require('async_hooks');
51cb0ef41Sopenharmony_ciconst test_async = require(`./build/${common.buildType}/test_async`);
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst events = [];
81cb0ef41Sopenharmony_cilet testId;
91cb0ef41Sopenharmony_ciconst initAsyncId = async_hooks.executionAsyncId();
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciasync_hooks.createHook({
121cb0ef41Sopenharmony_ci  init(id, provider, triggerAsyncId, resource) {
131cb0ef41Sopenharmony_ci    if (provider === 'TestResource') {
141cb0ef41Sopenharmony_ci      testId = id;
151cb0ef41Sopenharmony_ci      events.push({ type: 'init', id, provider, triggerAsyncId, resource });
161cb0ef41Sopenharmony_ci    }
171cb0ef41Sopenharmony_ci  },
181cb0ef41Sopenharmony_ci  before(id) {
191cb0ef41Sopenharmony_ci    if (testId === id) {
201cb0ef41Sopenharmony_ci      events.push({ type: 'before', id });
211cb0ef41Sopenharmony_ci    }
221cb0ef41Sopenharmony_ci  },
231cb0ef41Sopenharmony_ci  after(id) {
241cb0ef41Sopenharmony_ci    if (testId === id) {
251cb0ef41Sopenharmony_ci      events.push({ type: 'after', id });
261cb0ef41Sopenharmony_ci    }
271cb0ef41Sopenharmony_ci  },
281cb0ef41Sopenharmony_ci  destroy(id) {
291cb0ef41Sopenharmony_ci    if (testId === id) {
301cb0ef41Sopenharmony_ci      events.push({ type: 'destroy', id });
311cb0ef41Sopenharmony_ci    }
321cb0ef41Sopenharmony_ci  },
331cb0ef41Sopenharmony_ci}).enable();
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ciconst resource = { foo: 'foo' };
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_cievents.push({ type: 'start' });
381cb0ef41Sopenharmony_citest_async.Test(5, resource, common.mustCall(function(err, val) {
391cb0ef41Sopenharmony_ci  assert.strictEqual(err, null);
401cb0ef41Sopenharmony_ci  assert.strictEqual(val, 10);
411cb0ef41Sopenharmony_ci  events.push({ type: 'complete' });
421cb0ef41Sopenharmony_ci  process.nextTick(common.mustCall());
431cb0ef41Sopenharmony_ci}));
441cb0ef41Sopenharmony_cievents.push({ type: 'scheduled' });
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_ciprocess.on('exit', () => {
471cb0ef41Sopenharmony_ci  assert.deepStrictEqual(events, [
481cb0ef41Sopenharmony_ci    { type: 'start' },
491cb0ef41Sopenharmony_ci    { type: 'init',
501cb0ef41Sopenharmony_ci      id: testId,
511cb0ef41Sopenharmony_ci      provider: 'TestResource',
521cb0ef41Sopenharmony_ci      triggerAsyncId: initAsyncId,
531cb0ef41Sopenharmony_ci      resource },
541cb0ef41Sopenharmony_ci    { type: 'scheduled' },
551cb0ef41Sopenharmony_ci    { type: 'before', id: testId },
561cb0ef41Sopenharmony_ci    { type: 'complete' },
571cb0ef41Sopenharmony_ci    { type: 'after', id: testId },
581cb0ef41Sopenharmony_ci    { type: 'destroy', id: testId },
591cb0ef41Sopenharmony_ci  ]);
601cb0ef41Sopenharmony_ci});
61