0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-25 08:19:38 +01:00
nodejs/test/async-hooks/test-async-exec-resource-http-agent.js
psj-tar-gz 491855c82b
test: add http agent to executionAsyncResource
Refs: https://github.com/nodejs/node/blob/HEAD/test/async-hooks/test-async-exec-resource-http.js
Signed-off-by: psj-tar-gz <lyricalllmagical@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/34966
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2024-05-11 10:45:09 +02:00

37 lines
810 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('node:assert');
const {
executionAsyncResource,
executionAsyncId,
createHook,
} = require('node:async_hooks');
const http = require('node:http');
const hooked = {};
createHook({
init(asyncId, type, triggerAsyncId, resource) {
hooked[asyncId] = resource;
},
}).enable();
const agent = new http.Agent({
maxSockets: 1,
});
const server = http.createServer((req, res) => {
res.end('ok');
});
server.listen(0, common.mustCall(() => {
assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]);
http.get({ agent, port: server.address().port }, common.mustCall(() => {
assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]);
server.close();
agent.destroy();
}));
}));