Skip to content

Commit 311bdc6

Browse files
psj-tar-gzmarco-ippolito
authored andcommittedJun 17, 2024
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: #34966 Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 48c15d0 commit 311bdc6

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
5+
const assert = require('node:assert');
6+
const {
7+
executionAsyncResource,
8+
executionAsyncId,
9+
createHook,
10+
} = require('node:async_hooks');
11+
const http = require('node:http');
12+
13+
const hooked = {};
14+
createHook({
15+
init(asyncId, type, triggerAsyncId, resource) {
16+
hooked[asyncId] = resource;
17+
},
18+
}).enable();
19+
20+
const agent = new http.Agent({
21+
maxSockets: 1,
22+
});
23+
24+
const server = http.createServer((req, res) => {
25+
res.end('ok');
26+
});
27+
28+
server.listen(0, common.mustCall(() => {
29+
assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]);
30+
31+
http.get({ agent, port: server.address().port }, common.mustCall(() => {
32+
assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]);
33+
server.close();
34+
agent.destroy();
35+
}));
36+
}));

0 commit comments

Comments
 (0)
Please sign in to comment.