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-promise-run-stores.js
Stephen Belanger cf83caeb57
test: verify tracePromise does not do runStores
PR-URL: https://github.com/nodejs/node/pull/47349
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2023-04-03 16:44:50 +00:00

32 lines
985 B
JavaScript

'use strict';
const common = require('../common');
const { setTimeout } = require('node:timers/promises');
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.mustNotCall(() => {
return secondContext;
}));
assert.strictEqual(store.getStore(), undefined);
channel.tracePromise(common.mustCall(async () => {
assert.deepStrictEqual(store.getStore(), firstContext);
await setTimeout(1);
// Should _not_ switch to second context as promises don't have an "after"
// point at which to do a runStores.
assert.deepStrictEqual(store.getStore(), firstContext);
}));
assert.strictEqual(store.getStore(), undefined);