mirror of
https://github.com/nodejs/node.git
synced 2024-11-24 20:29:23 +01:00
cf83caeb57
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>
32 lines
985 B
JavaScript
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);
|