test: refactor trace event category tests
- Add descriptions - Filter out the relevant traces for testing, ignore the irrelevant ones. PR-URL: https://github.com/nodejs/node/pull/26605 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
parent
d398e8988c
commit
e2a2f9398e
@ -1,5 +1,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
// This tests that tracing can be enabled dynamically with the
|
||||||
|
// trace_events module.
|
||||||
|
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
try {
|
try {
|
||||||
require('trace_events');
|
require('trace_events');
|
||||||
@ -11,7 +14,6 @@ const assert = require('assert');
|
|||||||
const cp = require('child_process');
|
const cp = require('child_process');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const util = require('util');
|
|
||||||
|
|
||||||
const enable = `require("trace_events").createTracing(
|
const enable = `require("trace_events").createTracing(
|
||||||
{ categories: ["node.async_hooks"] }).enable();`;
|
{ categories: ["node.async_hooks"] }).enable();`;
|
||||||
@ -32,36 +34,16 @@ const proc = cp.spawnSync(
|
|||||||
'NODE_DEBUG': 'tracing'
|
'NODE_DEBUG': 'tracing'
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
console.log(proc.signal);
|
|
||||||
console.log(proc.stderr.toString());
|
|
||||||
assert.strictEqual(proc.status, 0);
|
|
||||||
|
|
||||||
|
console.log('process exit with signal:', proc.signal);
|
||||||
|
console.log('process stderr:', proc.stderr.toString());
|
||||||
|
|
||||||
|
assert.strictEqual(proc.status, 0);
|
||||||
assert(fs.existsSync(filename));
|
assert(fs.existsSync(filename));
|
||||||
const data = fs.readFileSync(filename, 'utf-8');
|
const data = fs.readFileSync(filename, 'utf-8');
|
||||||
const traces = JSON.parse(data).traceEvents;
|
const traces = JSON.parse(data).traceEvents;
|
||||||
assert(traces.length > 0);
|
|
||||||
// V8 trace events should be generated.
|
|
||||||
assert(!traces.some((trace) => {
|
|
||||||
if (trace.pid !== proc.pid)
|
|
||||||
return false;
|
|
||||||
if (trace.cat !== 'v8')
|
|
||||||
return false;
|
|
||||||
if (trace.name !== 'V8.ScriptCompiler')
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}));
|
|
||||||
|
|
||||||
// C++ async_hooks trace events should be generated.
|
function filterTimeoutTraces(trace) {
|
||||||
assert(traces.some((trace) => {
|
|
||||||
if (trace.pid !== proc.pid)
|
|
||||||
return false;
|
|
||||||
if (trace.cat !== 'node,node.async_hooks')
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}));
|
|
||||||
|
|
||||||
// JavaScript async_hooks trace events should be generated.
|
|
||||||
assert(traces.some((trace) => {
|
|
||||||
if (trace.pid !== proc.pid)
|
if (trace.pid !== proc.pid)
|
||||||
return false;
|
return false;
|
||||||
if (trace.cat !== 'node,node.async_hooks')
|
if (trace.cat !== 'node,node.async_hooks')
|
||||||
@ -69,18 +51,14 @@ assert(traces.some((trace) => {
|
|||||||
if (trace.name !== 'Timeout')
|
if (trace.name !== 'Timeout')
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}));
|
}
|
||||||
|
|
||||||
// Check args in init events
|
{
|
||||||
const initEvents = traces.filter((trace) => {
|
const timeoutTraces = traces.filter(filterTimeoutTraces);
|
||||||
return (trace.ph === 'b' && !trace.name.includes('_CALLBACK'));
|
assert.notDeepStrictEqual(timeoutTraces, []);
|
||||||
});
|
const threads = new Set();
|
||||||
for (const trace of initEvents) {
|
for (const trace of timeoutTraces) {
|
||||||
console.log(trace);
|
threads.add(trace.tid);
|
||||||
if (trace.args.data.executionAsyncId > 0 &&
|
|
||||||
trace.args.data.triggerAsyncId > 0) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
assert.fail('Unexpected initEvent: ',
|
assert.notDeepStrictEqual(timeoutTraces, []);
|
||||||
util.inspect(trace, { depth: Infinity }));
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
// This tests that enabling node.async_hooks in main threads also
|
||||||
|
// affects the workers.
|
||||||
|
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
try {
|
try {
|
||||||
require('trace_events');
|
require('trace_events');
|
||||||
@ -11,17 +14,18 @@ const assert = require('assert');
|
|||||||
const cp = require('child_process');
|
const cp = require('child_process');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const util = require('util');
|
|
||||||
|
|
||||||
const code =
|
const code =
|
||||||
'setTimeout(() => { for (var i = 0; i < 100000; i++) { "test" + i } }, 1)';
|
'setTimeout(() => { for (var i = 0; i < 100000; i++) { "test" + i } }, 1)';
|
||||||
const worker = `const { Worker } = require('worker_threads');
|
const worker =
|
||||||
|
`const { Worker } = require('worker_threads');
|
||||||
const worker = new Worker('${code}',
|
const worker = new Worker('${code}',
|
||||||
{ eval: true, stdout: true, stderr: true });
|
{ eval: true, stdout: true, stderr: true });
|
||||||
worker.stdout.on('data',
|
worker.stdout.on('data',
|
||||||
(chunk) => console.log('worker', chunk.toString()));
|
(chunk) => console.log('worker', chunk.toString()));
|
||||||
worker.stderr.on('data',
|
worker.stderr.on('data',
|
||||||
(chunk) => console.error('worker', chunk.toString()));`;
|
(chunk) => console.error('worker', chunk.toString()));
|
||||||
|
worker.on('exit', () => { ${code} })`;
|
||||||
|
|
||||||
const tmpdir = require('../common/tmpdir');
|
const tmpdir = require('../common/tmpdir');
|
||||||
const filename = path.join(tmpdir.path, 'node_trace.1.log');
|
const filename = path.join(tmpdir.path, 'node_trace.1.log');
|
||||||
@ -38,36 +42,15 @@ const proc = cp.spawnSync(
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(proc.signal);
|
console.log('process exit with signal:', proc.signal);
|
||||||
console.log(proc.stderr.toString());
|
console.log('process stderr:', proc.stderr.toString());
|
||||||
assert.strictEqual(proc.status, 0);
|
|
||||||
|
|
||||||
|
assert.strictEqual(proc.status, 0);
|
||||||
assert(fs.existsSync(filename));
|
assert(fs.existsSync(filename));
|
||||||
const data = fs.readFileSync(filename, 'utf-8');
|
const data = fs.readFileSync(filename, 'utf-8');
|
||||||
const traces = JSON.parse(data).traceEvents;
|
const traces = JSON.parse(data).traceEvents;
|
||||||
assert(traces.length > 0);
|
|
||||||
// V8 trace events should be generated.
|
|
||||||
assert(!traces.some((trace) => {
|
|
||||||
if (trace.pid !== proc.pid)
|
|
||||||
return false;
|
|
||||||
if (trace.cat !== 'v8')
|
|
||||||
return false;
|
|
||||||
if (trace.name !== 'V8.ScriptCompiler')
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}));
|
|
||||||
|
|
||||||
// C++ async_hooks trace events should be generated.
|
function filterTimeoutTraces(trace) {
|
||||||
assert(traces.some((trace) => {
|
|
||||||
if (trace.pid !== proc.pid)
|
|
||||||
return false;
|
|
||||||
if (trace.cat !== 'node,node.async_hooks')
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}));
|
|
||||||
|
|
||||||
// JavaScript async_hooks trace events should be generated.
|
|
||||||
assert(traces.some((trace) => {
|
|
||||||
if (trace.pid !== proc.pid)
|
if (trace.pid !== proc.pid)
|
||||||
return false;
|
return false;
|
||||||
if (trace.cat !== 'node,node.async_hooks')
|
if (trace.cat !== 'node,node.async_hooks')
|
||||||
@ -75,23 +58,16 @@ assert(traces.some((trace) => {
|
|||||||
if (trace.name !== 'Timeout')
|
if (trace.name !== 'Timeout')
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}));
|
}
|
||||||
|
|
||||||
// Check args in init events
|
{
|
||||||
const initEvents = traces.filter((trace) => {
|
const timeoutTraces = traces.filter(filterTimeoutTraces);
|
||||||
return (trace.ph === 'b' && !trace.name.includes('_CALLBACK'));
|
assert.notDeepStrictEqual(timeoutTraces, []);
|
||||||
});
|
const threads = new Set();
|
||||||
|
for (const trace of timeoutTraces) {
|
||||||
for (const trace of initEvents) {
|
threads.add(trace.tid);
|
||||||
if (trace.name === 'MESSAGEPORT' &&
|
|
||||||
trace.args.data.executionAsyncId === 0 &&
|
|
||||||
trace.args.data.triggerAsyncId === 0) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
if (trace.args.data.executionAsyncId > 0 &&
|
assert.notDeepStrictEqual(timeoutTraces, []);
|
||||||
trace.args.data.triggerAsyncId > 0) {
|
console.log('Threads with Timeout traces:', threads);
|
||||||
continue;
|
assert.strictEqual(threads.size, 2);
|
||||||
}
|
|
||||||
assert.fail('Unexpected initEvent: ',
|
|
||||||
util.inspect(trace, { depth: Infinity }));
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user