1'use strict'; 2 3const common = require('../common'); 4const { setTimeout } = require('node:timers/promises'); 5const { AsyncLocalStorage } = require('async_hooks'); 6const dc = require('diagnostics_channel'); 7const assert = require('assert'); 8 9const channel = dc.tracingChannel('test'); 10const store = new AsyncLocalStorage(); 11 12const firstContext = { foo: 'bar' }; 13const secondContext = { baz: 'buz' }; 14 15channel.start.bindStore(store, common.mustCall(() => { 16 return firstContext; 17})); 18 19channel.asyncStart.bindStore(store, common.mustNotCall(() => { 20 return secondContext; 21})); 22 23assert.strictEqual(store.getStore(), undefined); 24channel.tracePromise(common.mustCall(async () => { 25 assert.deepStrictEqual(store.getStore(), firstContext); 26 await setTimeout(1); 27 // Should _not_ switch to second context as promises don't have an "after" 28 // point at which to do a runStores. 29 assert.deepStrictEqual(store.getStore(), firstContext); 30})); 31assert.strictEqual(store.getStore(), undefined); 32