Skip to content

Commit 55f0830

Browse files
psj-tar-gzaduh95
authored andcommitted
test: add http agent to executionAsyncResource
I added a testcase about executionAsyncResource with Http Agent. Refs: https://github.com/nodejs/node/blob/master/test/async-hooks/test-async-exec-resource-http.js Signed-off-by: psj-tar-gz <[email protected]>
1 parent c7e4209 commit 55f0830

File tree

1 file changed

+35
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)