11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_cirequire('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst { 51cb0ef41Sopenharmony_ci executionAsyncResource, 61cb0ef41Sopenharmony_ci executionAsyncId, 71cb0ef41Sopenharmony_ci createHook, 81cb0ef41Sopenharmony_ci} = require('async_hooks'); 91cb0ef41Sopenharmony_ciconst http = require('http'); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciconst hooked = {}; 121cb0ef41Sopenharmony_cicreateHook({ 131cb0ef41Sopenharmony_ci init(asyncId, type, triggerAsyncId, resource) { 141cb0ef41Sopenharmony_ci hooked[asyncId] = resource; 151cb0ef41Sopenharmony_ci }, 161cb0ef41Sopenharmony_ci}).enable(); 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ciconst server = http.createServer((req, res) => { 191cb0ef41Sopenharmony_ci res.write('hello'); 201cb0ef41Sopenharmony_ci setTimeout(() => { 211cb0ef41Sopenharmony_ci res.end(' world!'); 221cb0ef41Sopenharmony_ci }, 1000); 231cb0ef41Sopenharmony_ci}); 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ciserver.listen(0, () => { 261cb0ef41Sopenharmony_ci assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]); 271cb0ef41Sopenharmony_ci http.get({ port: server.address().port }, (res) => { 281cb0ef41Sopenharmony_ci assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]); 291cb0ef41Sopenharmony_ci res.on('data', () => { 301cb0ef41Sopenharmony_ci assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]); 311cb0ef41Sopenharmony_ci }); 321cb0ef41Sopenharmony_ci res.on('end', () => { 331cb0ef41Sopenharmony_ci assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]); 341cb0ef41Sopenharmony_ci server.close(); 351cb0ef41Sopenharmony_ci }); 361cb0ef41Sopenharmony_ci }); 371cb0ef41Sopenharmony_ci}); 38