Skip to content

Commit

Permalink
test: add http agent to executionAsyncResource
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
psj-tar-gz authored and aduh95 committed May 5, 2024
1 parent c7e4209 commit 55f0830
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 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,35 @@
'use strict';

const assert = require('assert');

const {
executionAsyncResource,
executionAsyncId,
createHook,
} = require('async_hooks');
const http = require('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, () => {
assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]);

http.get({ agent, port: server.address().port }, () => {
assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]);
server.close();
agent.destroy();
});
});

0 comments on commit 55f0830

Please sign in to comment.