0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-24 20:29:23 +01:00
nodejs/test/parallel/test-diagnostics-channel-tracing-channel-callback-run-stores.js
Stephen Belanger fe751df537
lib: add tracing channel to diagnostics_channel
PR-URL: https://github.com/nodejs/node/pull/44943
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Bryan English <bryan@bryanenglish.com>
2023-03-31 17:40:30 +00:00

30 lines
846 B
JavaScript

'use strict';
const common = require('../common');
const { AsyncLocalStorage } = require('async_hooks');
const dc = require('diagnostics_channel');
const assert = require('assert');
const channel = dc.tracingChannel('test');
const store = new AsyncLocalStorage();
const firstContext = { foo: 'bar' };
const secondContext = { baz: 'buz' };
channel.start.bindStore(store, common.mustCall(() => {
return firstContext;
}));
channel.asyncStart.bindStore(store, common.mustCall(() => {
return secondContext;
}));
assert.strictEqual(store.getStore(), undefined);
channel.traceCallback(common.mustCall((cb) => {
assert.deepStrictEqual(store.getStore(), firstContext);
setImmediate(cb);
}), 0, {}, null, common.mustCall(() => {
assert.deepStrictEqual(store.getStore(), secondContext);
}));
assert.strictEqual(store.getStore(), undefined);