From 4de448397fb41b7bea7f94050b269540ec917450 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 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 --- .../test-async-exec-resource-http-agent.js | 35 +++++++++++++++++++ 1 file changed, 35 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..a0267843b75fb9 --- /dev/null +++ b/test/async-hooks/test-async-exec-resource-http-agent.js @@ -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(); + }); +});