xref: /third_party/node/test/async-hooks/test-async-exec-resource-http.js
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/test/async-hooks/
11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_cirequire('../common');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ciconst {
61cb0ef41Sopenharmony_ci  executionAsyncResource,
71cb0ef41Sopenharmony_ci  executionAsyncId,
81cb0ef41Sopenharmony_ci  createHook,
91cb0ef41Sopenharmony_ci} = require('async_hooks');
101cb0ef41Sopenharmony_ciconst http = require('http');
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ciconst hooked = {};
131cb0ef41Sopenharmony_cicreateHook({
141cb0ef41Sopenharmony_ci  init(asyncId, type, triggerAsyncId, resource) {
151cb0ef41Sopenharmony_ci    hooked[asyncId] = resource;
161cb0ef41Sopenharmony_ci  },
171cb0ef41Sopenharmony_ci}).enable();
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ciconst server = http.createServer((req, res) => {
201cb0ef41Sopenharmony_ci  res.end('ok');
211cb0ef41Sopenharmony_ci});
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ciserver.listen(0, () => {
241cb0ef41Sopenharmony_ci  assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]);
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci  http.get({ port: server.address().port }, () => {
271cb0ef41Sopenharmony_ci    assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]);
281cb0ef41Sopenharmony_ci    server.close();
291cb0ef41Sopenharmony_ci  });
301cb0ef41Sopenharmony_ci});
31

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