From 17ec6d16ff8a3c09bff15d68603c8ae76e620314 Mon Sep 17 00:00:00 2001 From: psj-tar-gz Date: Sat, 29 Aug 2020 18:04:11 +0900 Subject: [PATCH] test: add http agent to `executionAsyncResource` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs: https://github.com/nodejs/node/blob/HEAD/test/async-hooks/test-async-exec-resource-http.js Signed-off-by: psj-tar-gz PR-URL: https://github.com/nodejs/node/pull/34966 Reviewed-By: Gerhard Stöbich Reviewed-By: Anna Henningsen --- .../test-async-exec-resource-http-agent.js | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 test/async-hooks/test-async-exec-resource-http-agent.js 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(); + })); +}));