11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst { AsyncLocalStorage } = require('async_hooks'); 51cb0ef41Sopenharmony_ciconst http = require('http'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst asyncLocalStorage = new AsyncLocalStorage(); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciconst agent = new http.Agent({ 101cb0ef41Sopenharmony_ci maxSockets: 1, 111cb0ef41Sopenharmony_ci}); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ciconst N = 3; 141cb0ef41Sopenharmony_cilet responses = 0; 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ciconst server = http.createServer(common.mustCall((req, res) => { 171cb0ef41Sopenharmony_ci res.end('ok'); 181cb0ef41Sopenharmony_ci}, N)); 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => { 211cb0ef41Sopenharmony_ci const port = server.address().port; 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci for (let i = 0; i < N; i++) { 241cb0ef41Sopenharmony_ci asyncLocalStorage.run(i, () => { 251cb0ef41Sopenharmony_ci http.get({ agent, port }, common.mustCall((res) => { 261cb0ef41Sopenharmony_ci assert.strictEqual(asyncLocalStorage.getStore(), i); 271cb0ef41Sopenharmony_ci if (++responses === N) { 281cb0ef41Sopenharmony_ci server.close(); 291cb0ef41Sopenharmony_ci agent.destroy(); 301cb0ef41Sopenharmony_ci } 311cb0ef41Sopenharmony_ci res.resume(); 321cb0ef41Sopenharmony_ci })); 331cb0ef41Sopenharmony_ci }); 341cb0ef41Sopenharmony_ci } 351cb0ef41Sopenharmony_ci})); 36