11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciconst { setTimeout } = require('node:timers/promises'); 51cb0ef41Sopenharmony_ciconst { AsyncLocalStorage } = require('async_hooks'); 61cb0ef41Sopenharmony_ciconst dc = require('diagnostics_channel'); 71cb0ef41Sopenharmony_ciconst assert = require('assert'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciconst channel = dc.tracingChannel('test'); 101cb0ef41Sopenharmony_ciconst store = new AsyncLocalStorage(); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciconst firstContext = { foo: 'bar' }; 131cb0ef41Sopenharmony_ciconst secondContext = { baz: 'buz' }; 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_cichannel.start.bindStore(store, common.mustCall(() => { 161cb0ef41Sopenharmony_ci return firstContext; 171cb0ef41Sopenharmony_ci})); 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_cichannel.asyncStart.bindStore(store, common.mustNotCall(() => { 201cb0ef41Sopenharmony_ci return secondContext; 211cb0ef41Sopenharmony_ci})); 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ciassert.strictEqual(store.getStore(), undefined); 241cb0ef41Sopenharmony_cichannel.tracePromise(common.mustCall(async () => { 251cb0ef41Sopenharmony_ci assert.deepStrictEqual(store.getStore(), firstContext); 261cb0ef41Sopenharmony_ci await setTimeout(1); 271cb0ef41Sopenharmony_ci // Should _not_ switch to second context as promises don't have an "after" 281cb0ef41Sopenharmony_ci // point at which to do a runStores. 291cb0ef41Sopenharmony_ci assert.deepStrictEqual(store.getStore(), firstContext); 301cb0ef41Sopenharmony_ci})); 311cb0ef41Sopenharmony_ciassert.strictEqual(store.getStore(), undefined); 32