Skip to content

Commit

Permalink
test: add http agent to executionAsyncResource
Browse files Browse the repository at this point in the history
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: #34966
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
psj-tar-gz authored and marco-ippolito committed Jun 17, 2024
1 parent 48c15d0 commit 311bdc6
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/async-hooks/test-async-exec-resource-http-agent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'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();
}));
}));

0 comments on commit 311bdc6

Please sign in to comment.