Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 28758b8

Browse filesBrowse files
joyeecheungrvagg
authored andcommitted
test: add test for dynamically enabling node.async_hooks tracing
PR-URL: #26062 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent dcbd907 commit 28758b8
Copy full SHA for 28758b8

File tree

Expand file treeCollapse file tree

1 file changed

+83
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+83
-0
lines changed
Open diff view settings
Collapse file
+83Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
if (!process.binding('config').hasTracing)
5+
common.skip('missing trace events');
6+
7+
const assert = require('assert');
8+
const cp = require('child_process');
9+
const fs = require('fs');
10+
const path = require('path');
11+
const util = require('util');
12+
13+
const enable = `require("trace_events").createTracing(
14+
{ categories: ["node.async_hooks"] }).enable();`;
15+
const code =
16+
'setTimeout(() => { for (var i = 0; i < 100000; i++) { "test" + i } }, 1)';
17+
18+
const tmpdir = require('../common/tmpdir');
19+
const filename = path.join(tmpdir.path, 'node_trace.1.log');
20+
21+
tmpdir.refresh();
22+
const proc = cp.spawnSync(
23+
process.execPath,
24+
['-e', enable + code ],
25+
{
26+
cwd: tmpdir.path,
27+
env: Object.assign({}, process.env, {
28+
'NODE_DEBUG_NATIVE': 'tracing',
29+
'NODE_DEBUG': 'tracing'
30+
})
31+
});
32+
console.log(proc.signal);
33+
console.log(proc.stderr.toString());
34+
assert.strictEqual(proc.status, 0);
35+
36+
assert(fs.existsSync(filename));
37+
const data = fs.readFileSync(filename, 'utf-8');
38+
const traces = JSON.parse(data).traceEvents;
39+
assert(traces.length > 0);
40+
// V8 trace events should be generated.
41+
assert(!traces.some((trace) => {
42+
if (trace.pid !== proc.pid)
43+
return false;
44+
if (trace.cat !== 'v8')
45+
return false;
46+
if (trace.name !== 'V8.ScriptCompiler')
47+
return false;
48+
return true;
49+
}));
50+
51+
// C++ async_hooks trace events should be generated.
52+
assert(traces.some((trace) => {
53+
if (trace.pid !== proc.pid)
54+
return false;
55+
if (trace.cat !== 'node,node.async_hooks')
56+
return false;
57+
return true;
58+
}));
59+
60+
// JavaScript async_hooks trace events should be generated.
61+
assert(traces.some((trace) => {
62+
if (trace.pid !== proc.pid)
63+
return false;
64+
if (trace.cat !== 'node,node.async_hooks')
65+
return false;
66+
if (trace.name !== 'Timeout')
67+
return false;
68+
return true;
69+
}));
70+
71+
// Check args in init events
72+
const initEvents = traces.filter((trace) => {
73+
return (trace.ph === 'b' && !trace.name.includes('_CALLBACK'));
74+
});
75+
for (const trace of initEvents) {
76+
console.log(trace);
77+
if (trace.args.data.executionAsyncId > 0 &&
78+
trace.args.data.triggerAsyncId > 0) {
79+
continue;
80+
}
81+
assert.fail('Unexpected initEvent: ',
82+
util.inspect(trace, { depth: Infinity }));
83+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.