mirror of
https://github.com/nodejs/node.git
synced 2024-11-22 07:37:56 +01:00
cf46746b8a
PR-URL: https://github.com/nodejs/node/pull/45549 Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
36 lines
814 B
JavaScript
36 lines
814 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const { AsyncLocalStorage } = require('async_hooks');
|
|
const http = require('http');
|
|
|
|
const asyncLocalStorage = new AsyncLocalStorage();
|
|
|
|
const agent = new http.Agent({
|
|
maxSockets: 1,
|
|
});
|
|
|
|
const N = 3;
|
|
let responses = 0;
|
|
|
|
const server = http.createServer(common.mustCall((req, res) => {
|
|
res.end('ok');
|
|
}, N));
|
|
|
|
server.listen(0, common.mustCall(() => {
|
|
const port = server.address().port;
|
|
|
|
for (let i = 0; i < N; i++) {
|
|
asyncLocalStorage.run(i, () => {
|
|
http.get({ agent, port }, common.mustCall((res) => {
|
|
assert.strictEqual(asyncLocalStorage.getStore(), i);
|
|
if (++responses === N) {
|
|
server.close();
|
|
agent.destroy();
|
|
}
|
|
res.resume();
|
|
}));
|
|
});
|
|
}
|
|
}));
|