-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Expand file tree
/
Copy pathtest-async-exec-resource-http-32060.js
More file actions
37 lines (34 loc) · 1.04 KB
/
test-async-exec-resource-http-32060.js
File metadata and controls
37 lines (34 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict';
const common = require('../common');
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 server = http.createServer((req, res) => {
res.write('hello');
setTimeout(() => {
res.end(' world!');
}, 1000);
});
server.listen(0, common.mustCallAtLeast(() => {
assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]);
http.get({ port: server.address().port }, common.mustCallAtLeast((res) => {
assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]);
res.on('data', common.mustCallAtLeast(() => {
assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]);
}));
res.on('end', common.mustCall(() => {
assert.strictEqual(executionAsyncResource(), hooked[executionAsyncId()]);
server.close();
}));
}));
}));