diff options
author | Kelvin Jin <kelvinjin@google.com> | 2018-12-10 20:44:18 +0000 |
---|---|---|
committer | Ali Ijaz Sheikh <ofrobots@google.com> | 2019-02-14 12:10:09 -0800 |
commit | 582c0d5a092b04616fef4b11b0fd893c181356f1 (patch) | |
tree | 9b81e3e3d701e561f957c09adb200ca95198865d /test | |
parent | 7d60b6b21b7d47d22ac7a321eb5b47cf90d63ecf (diff) | |
download | android-node-v8-582c0d5a092b04616fef4b11b0fd893c181356f1.tar.gz android-node-v8-582c0d5a092b04616fef4b11b0fd893c181356f1.tar.bz2 android-node-v8-582c0d5a092b04616fef4b11b0fd893c181356f1.zip |
trace_events: fix trace events JS API writing
The Trace Events JS API isn't functional if none of
--trace-events-enabled or --trace-event-categories is passed as a CLI
argument. This commit fixes that.
In addition, we currently don't test the trace_events JS API in the
casewhere no CLI args are provided. This commit adds that test.
Fixes https://github.com/nodejs/node/issues/24944
PR-URL: https://github.com/nodejs/node/pull/24945
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-trace-events-api.js | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/test/parallel/test-trace-events-api.js b/test/parallel/test-trace-events-api.js index 346f943b9c..cf11daa6ed 100644 --- a/test/parallel/test-trace-events-api.js +++ b/test/parallel/test-trace-events-api.js @@ -17,8 +17,17 @@ const { getEnabledCategories } = require('trace_events'); +function getEnabledCategoriesFromCommandLine() { + const indexOfCatFlag = process.execArgv.indexOf('--trace-event-categories'); + if (indexOfCatFlag === -1) { + return undefined; + } else { + return process.execArgv[indexOfCatFlag + 1]; + } +} + const isChild = process.argv[2] === 'child'; -const enabledCategories = isChild ? 'foo' : undefined; +const enabledCategories = getEnabledCategoriesFromCommandLine(); assert.strictEqual(getEnabledCategories(), enabledCategories); [1, 'foo', true, false, null, undefined].forEach((i) => { @@ -51,7 +60,9 @@ tracing.enable(); // purposefully enable twice to test calling twice assert.strictEqual(tracing.enabled, true); assert.strictEqual(getEnabledCategories(), - isChild ? 'foo,node.perf' : 'node.perf'); + [ + ...[enabledCategories].filter((_) => !!_), 'node.perf' + ].join(',')); tracing.disable(); assert.strictEqual(tracing.enabled, false); @@ -106,7 +117,15 @@ if (isChild) { } } + testApiInChildProcess([], () => { + testApiInChildProcess(['--trace-event-categories', 'foo']); + }); +} + +function testApiInChildProcess(execArgs, cb) { tmpdir.refresh(); + // Save the current directory so we can chdir back to it later + const parentDir = process.cwd(); process.chdir(tmpdir.path); const expectedMarks = ['A', 'B']; @@ -121,15 +140,14 @@ if (isChild) { const proc = cp.fork(__filename, ['child'], - { execArgv: [ '--expose-gc', - '--trace-event-categories', - 'foo' ] }); + { execArgv: [ '--expose-gc', ...execArgs ] }); proc.once('exit', common.mustCall(() => { const file = path.join(tmpdir.path, 'node_trace.1.log'); assert(fs.existsSync(file)); fs.readFile(file, common.mustCall((err, data) => { + assert.ifError(err); const traces = JSON.parse(data.toString()).traceEvents .filter((trace) => trace.cat !== '__metadata'); assert.strictEqual(traces.length, @@ -160,6 +178,8 @@ if (isChild) { assert.fail('Unexpected trace event phase'); } }); + process.chdir(parentDir); + cb && process.nextTick(cb); })); })); } |