1'use strict';
2
3const common = require('../common');
4const { AsyncLocalStorage } = require('async_hooks');
5const dc = require('diagnostics_channel');
6const assert = require('assert');
7
8const channel = dc.tracingChannel('test');
9const store = new AsyncLocalStorage();
10
11const firstContext = { foo: 'bar' };
12const secondContext = { baz: 'buz' };
13
14channel.start.bindStore(store, common.mustCall(() => {
15  return firstContext;
16}));
17
18channel.asyncStart.bindStore(store, common.mustCall(() => {
19  return secondContext;
20}));
21
22assert.strictEqual(store.getStore(), undefined);
23channel.traceCallback(common.mustCall((cb) => {
24  assert.deepStrictEqual(store.getStore(), firstContext);
25  setImmediate(cb);
26}), 0, {}, null, common.mustCall(() => {
27  assert.deepStrictEqual(store.getStore(), secondContext);
28}));
29assert.strictEqual(store.getStore(), undefined);
30