xref: /third_party/node/test/async-hooks/test-async-exec-resource-http.js (revision 1cb0ef41)
  • Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/test/async-hooks/
1'use strict';
2
3require('../common');
4const assert = require('assert');
5const {
6  executionAsyncResource,
7  executionAsyncId,
8  createHook,
9} = require('async_hooks');
10const http = require('http');
11
12const hooked = {};
13createHook({
14  init(asyncId, type, triggerAsyncId, resource) {
15    hooked[asyncId] = resource;
16  },
17}).enable();
18
19const server = http.createServer((req, res) => {
20  res.end('ok');
21});
22
23server.listen(0, () => {
24  assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]);
25
26  http.get({ port: server.address().port }, () => {
27    assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]);
28    server.close();
29  });
30});
31

Indexes created Thu Nov 07 10:32:03 CST 2024