diff --git a/test/async-hooks/test-async-exec-resource-http-agent.js b/test/async-hooks/test-async-exec-resource-http-agent.js new file mode 100644 index 00000000000000..abc2df3a193052 --- /dev/null +++ b/test/async-hooks/test-async-exec-resource-http-agent.js @@ -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(); + })); +}));