test: enable trace-events tests for workers

Use the `cwd` option for `child_process` instead of `process.chdir()`
to enable the trace events tests to run on workers.

PR-URL: https://github.com/nodejs/node/pull/23698
Refs: https://github.com/nodejs/node/pull/23674#discussion_r225335819
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
Richard Lau 2018-10-16 13:28:52 -04:00 committed by Daniel Bevenius
parent 15c336684f
commit 23f8b7d334
15 changed files with 48 additions and 84 deletions

View File

@ -3,20 +3,18 @@ const common = require('../common');
const assert = require('assert'); 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');
if (!common.isMainThread)
common.skip('process.chdir is not available in Workers');
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 FILE_NAME = 'node_trace.1.log';
const tmpdir = require('../common/tmpdir'); const tmpdir = require('../common/tmpdir');
tmpdir.refresh(); tmpdir.refresh();
process.chdir(tmpdir.path); const FILE_NAME = path.join(tmpdir.path, 'node_trace.1.log');
const proc = cp.spawn(process.execPath, const proc = cp.spawn(process.execPath,
[ '--trace-events-enabled', '-e', CODE ]); [ '--trace-events-enabled', '-e', CODE ],
{ cwd: tmpdir.path });
proc.once('exit', common.mustCall(() => { proc.once('exit', common.mustCall(() => {
assert(fs.existsSync(FILE_NAME)); assert(fs.existsSync(FILE_NAME));

View File

@ -5,8 +5,7 @@ const common = require('../common');
if (!process.binding('config').hasTracing) if (!process.binding('config').hasTracing)
common.skip('missing trace events'); common.skip('missing trace events');
if (!common.isMainThread) common.skipIfWorker(); // https://github.com/nodejs/node/issues/22767
common.skip('process.chdir is not available in Workers');
const assert = require('assert'); const assert = require('assert');
const cp = require('child_process'); const cp = require('child_process');

View File

@ -3,22 +3,20 @@ const common = require('../common');
const assert = require('assert'); 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 util = require('util'); const util = require('util');
if (!common.isMainThread)
common.skip('process.chdir is not available in Workers');
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 FILE_NAME = 'node_trace.1.log';
const tmpdir = require('../common/tmpdir'); const tmpdir = require('../common/tmpdir');
tmpdir.refresh(); tmpdir.refresh();
process.chdir(tmpdir.path); const FILE_NAME = path.join(tmpdir.path, 'node_trace.1.log');
const proc = cp.spawn(process.execPath, const proc = cp.spawn(process.execPath,
[ '--trace-event-categories', 'node.async_hooks', [ '--trace-event-categories', 'node.async_hooks',
'-e', CODE ]); '-e', CODE ],
{ cwd: tmpdir.path });
proc.once('exit', common.mustCall(() => { proc.once('exit', common.mustCall(() => {
assert(fs.existsSync(FILE_NAME)); assert(fs.existsSync(FILE_NAME));

View File

@ -3,9 +3,7 @@ const common = require('../common');
const assert = require('assert'); 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');
if (!common.isMainThread)
common.skip('process.chdir is not available in Workers');
const CODE = ` const CODE = `
const { internalBinding } = require('internal/test/binding'); const { internalBinding } = require('internal/test/binding');
@ -18,17 +16,17 @@ const CODE = `
trace('b'.charCodeAt(0), 'missing', trace('b'.charCodeAt(0), 'missing',
'type-value', 10, {'extra-value': 20 }); 'type-value', 10, {'extra-value': 20 });
`; `;
const FILE_NAME = 'node_trace.1.log';
const tmpdir = require('../common/tmpdir'); const tmpdir = require('../common/tmpdir');
tmpdir.refresh(); tmpdir.refresh();
process.chdir(tmpdir.path); const FILE_NAME = path.join(tmpdir.path, 'node_trace.1.log');
const proc = cp.spawn(process.execPath, const proc = cp.spawn(process.execPath,
[ '--trace-event-categories', 'custom', [ '--trace-event-categories', 'custom',
'--no-warnings', '--no-warnings',
'--expose-internals', '--expose-internals',
'-e', CODE ]); '-e', CODE ],
{ cwd: tmpdir.path });
proc.once('exit', common.mustCall(() => { proc.once('exit', common.mustCall(() => {
assert(fs.existsSync(FILE_NAME)); assert(fs.existsSync(FILE_NAME));

View File

@ -2,13 +2,10 @@
const common = require('../common'); const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const cp = require('child_process'); const cp = require('child_process');
const path = require('path');
const fs = require('fs'); const fs = require('fs');
const path = require('path');
const tmpdir = require('../common/tmpdir'); const tmpdir = require('../common/tmpdir');
if (!common.isMainThread)
common.skip('process.chdir is not available in Workers');
const names = [ const names = [
'environment', 'environment',
'nodeStart', 'nodeStart',
@ -30,10 +27,10 @@ if (process.argv[2] === 'child') {
1 + 1; 1 + 1;
} else { } else {
tmpdir.refresh(); tmpdir.refresh();
process.chdir(tmpdir.path);
const proc = cp.fork(__filename, const proc = cp.fork(__filename,
[ 'child' ], { [ 'child' ], {
cwd: tmpdir.path,
execArgv: [ execArgv: [
'--trace-event-categories', '--trace-event-categories',
'node.bootstrap' 'node.bootstrap'

View File

@ -3,9 +3,6 @@ const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const cp = require('child_process'); const cp = require('child_process');
if (!common.isMainThread)
common.skip('process.chdir is not available in Workers');
const CODE = ` const CODE = `
const { internalBinding } = require('internal/test/binding'); const { internalBinding } = require('internal/test/binding');
const { isTraceCategoryEnabled } = internalBinding('trace_events'); const { isTraceCategoryEnabled } = internalBinding('trace_events');
@ -16,7 +13,6 @@ const CODE = `
const tmpdir = require('../common/tmpdir'); const tmpdir = require('../common/tmpdir');
tmpdir.refresh(); tmpdir.refresh();
process.chdir(tmpdir.path);
const procEnabled = cp.spawn( const procEnabled = cp.spawn(
process.execPath, process.execPath,
@ -25,7 +21,8 @@ const procEnabled = cp.spawn(
// emits a warning. // emits a warning.
'--no-warnings', '--no-warnings',
'--expose-internals', '--expose-internals',
'-e', CODE ] '-e', CODE ],
{ cwd: tmpdir.path }
); );
let procEnabledOutput = ''; let procEnabledOutput = '';
@ -42,7 +39,8 @@ const procDisabled = cp.spawn(
// emits a warning. // emits a warning.
'--no-warnings', '--no-warnings',
'--expose-internals', '--expose-internals',
'-e', CODE ] '-e', CODE ],
{ cwd: tmpdir.path }
); );
let procDisabledOutput = ''; let procDisabledOutput = '';

View File

@ -4,12 +4,9 @@ const tmpdir = require('../common/tmpdir');
const assert = require('assert'); 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');
if (!common.isMainThread)
common.skip('process.chdir is not available in Workers');
tmpdir.refresh(); tmpdir.refresh();
process.chdir(tmpdir.path);
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)';
@ -20,10 +17,11 @@ const proc = cp.spawn(process.execPath, [
// eslint-disable-next-line no-template-curly-in-string // eslint-disable-next-line no-template-curly-in-string
'${pid}-${rotation}-${pid}-${rotation}.tracing.log', '${pid}-${rotation}-${pid}-${rotation}.tracing.log',
'-e', CODE '-e', CODE
]); ], { cwd: tmpdir.path });
proc.once('exit', common.mustCall(() => { proc.once('exit', common.mustCall(() => {
const expectedFilename = `${proc.pid}-1-${proc.pid}-1.tracing.log`; const expectedFilename = path.join(tmpdir.path,
`${proc.pid}-1-${proc.pid}-1.tracing.log`);
assert(fs.existsSync(expectedFilename)); assert(fs.existsSync(expectedFilename));
fs.readFile(expectedFilename, common.mustCall((err, data) => { fs.readFile(expectedFilename, common.mustCall((err, data) => {

View File

@ -3,13 +3,10 @@ const common = require('../common');
const assert = require('assert'); 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 util = require('util'); const util = require('util');
if (!common.isMainThread)
common.skip('process.chdir is not available in Workers');
const tests = new Array(); const tests = new Array();
const traceFile = 'node_trace.1.log';
let gid = 1; let gid = 1;
let uid = 1; let uid = 1;
@ -119,14 +116,14 @@ if (common.canCreateSymLink()) {
const tmpdir = require('../common/tmpdir'); const tmpdir = require('../common/tmpdir');
tmpdir.refresh(); tmpdir.refresh();
process.chdir(tmpdir.path); const traceFile = path.join(tmpdir.path, 'node_trace.1.log');
for (const tr in tests) { for (const tr in tests) {
const proc = cp.spawnSync(process.execPath, const proc = cp.spawnSync(process.execPath,
[ '--trace-events-enabled', [ '--trace-events-enabled',
'--trace-event-categories', 'node.fs.sync', '--trace-event-categories', 'node.fs.sync',
'-e', tests[tr] ], '-e', tests[tr] ],
{ encoding: 'utf8' }); { cwd: tmpdir.path, encoding: 'utf8' });
// Some AIX versions don't support futimes or utimes, so skip. // Some AIX versions don't support futimes or utimes, so skip.
if (common.isAIX && proc.status !== 0 && tr === 'fs.sync.futimes') { if (common.isAIX && proc.status !== 0 && tr === 'fs.sync.futimes') {
continue; continue;

View File

@ -3,23 +3,21 @@ const common = require('../common');
const assert = require('assert'); 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');
if (!common.isMainThread)
common.skip('process.chdir is not available in Workers');
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);' +
'process.title = "foo"'; 'process.title = "foo"';
const FILE_NAME = 'node_trace.1.log';
const tmpdir = require('../common/tmpdir'); const tmpdir = require('../common/tmpdir');
tmpdir.refresh(); tmpdir.refresh();
process.chdir(tmpdir.path); const FILE_NAME = path.join(tmpdir.path, 'node_trace.1.log');
const proc = cp.spawn(process.execPath, const proc = cp.spawn(process.execPath,
[ '--trace-event-categories', 'node.perf.usertiming', [ '--trace-event-categories', 'node.perf.usertiming',
'--title=bar', '--title=bar',
'-e', CODE ]); '-e', CODE ],
{ cwd: tmpdir.path });
proc.once('exit', common.mustCall(() => { proc.once('exit', common.mustCall(() => {
assert(fs.existsSync(FILE_NAME)); assert(fs.existsSync(FILE_NAME));
fs.readFile(FILE_NAME, common.mustCall((err, data) => { fs.readFile(FILE_NAME, common.mustCall((err, data) => {

View File

@ -3,21 +3,19 @@ const common = require('../common');
const assert = require('assert'); 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');
if (!common.isMainThread)
common.skip('process.chdir is not available in Workers');
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 FILE_NAME = 'node_trace.1.log';
const tmpdir = require('../common/tmpdir'); const tmpdir = require('../common/tmpdir');
tmpdir.refresh(); tmpdir.refresh();
process.chdir(tmpdir.path); const FILE_NAME = path.join(tmpdir.path, 'node_trace.1.log');
const proc_no_categories = cp.spawn( const proc_no_categories = cp.spawn(
process.execPath, process.execPath,
[ '--trace-event-categories', '""', '-e', CODE ] [ '--trace-event-categories', '""', '-e', CODE ],
{ cwd: tmpdir.path }
); );
proc_no_categories.once('exit', common.mustCall(() => { proc_no_categories.once('exit', common.mustCall(() => {

View File

@ -2,13 +2,10 @@
const common = require('../common'); const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const cp = require('child_process'); const cp = require('child_process');
const path = require('path');
const fs = require('fs'); const fs = require('fs');
const path = require('path');
const tmpdir = require('../common/tmpdir'); const tmpdir = require('../common/tmpdir');
if (!common.isMainThread)
common.skip('process.chdir is not available in Workers');
if (process.argv[2] === 'child') { if (process.argv[2] === 'child') {
const { performance } = require('perf_hooks'); const { performance } = require('perf_hooks');
@ -25,7 +22,6 @@ if (process.argv[2] === 'child') {
ff(); // Will emit a timerify trace event ff(); // Will emit a timerify trace event
} else { } else {
tmpdir.refresh(); tmpdir.refresh();
process.chdir(tmpdir.path);
const expectedMarks = ['A', 'B']; const expectedMarks = ['A', 'B'];
const expectedBegins = [ const expectedBegins = [
@ -41,6 +37,7 @@ if (process.argv[2] === 'child') {
[ [
'child' 'child'
], { ], {
cwd: tmpdir.path,
execArgv: [ execArgv: [
'--trace-event-categories', '--trace-event-categories',
'node.perf' 'node.perf'

View File

@ -3,20 +3,16 @@ const common = require('../common');
const assert = require('assert'); 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');
if (!common.isMainThread)
common.skip('process.chdir is not available in Workers');
const tmpdir = require('../common/tmpdir'); const tmpdir = require('../common/tmpdir');
const FILE_NAME = 'node_trace.1.log';
tmpdir.refresh(); tmpdir.refresh();
process.chdir(tmpdir.path); const FILE_NAME = path.join(tmpdir.path, 'node_trace.1.log');
const proc = cp.spawn(process.execPath, const proc = cp.spawn(process.execPath,
[ '--trace-events-enabled', [ '--trace-events-enabled',
'-e', 'process.exit()' ]); '-e', 'process.exit()' ],
{ cwd: tmpdir.path });
proc.once('exit', common.mustCall(() => { proc.once('exit', common.mustCall(() => {
assert(fs.existsSync(FILE_NAME)); assert(fs.existsSync(FILE_NAME));

View File

@ -2,15 +2,12 @@
const common = require('../common'); const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const cp = require('child_process'); const cp = require('child_process');
const path = require('path');
const fs = require('fs'); const fs = require('fs');
const path = require('path');
const tmpdir = require('../common/tmpdir'); const tmpdir = require('../common/tmpdir');
common.disableCrashOnUnhandledRejection(); common.disableCrashOnUnhandledRejection();
if (!common.isMainThread)
common.skip('process.chdir is not available in Workers');
if (process.argv[2] === 'child') { if (process.argv[2] === 'child') {
const p = Promise.reject(1); // Handled later const p = Promise.reject(1); // Handled later
Promise.reject(2); // Unhandled Promise.reject(2); // Unhandled
@ -19,10 +16,10 @@ if (process.argv[2] === 'child') {
}); });
} else { } else {
tmpdir.refresh(); tmpdir.refresh();
process.chdir(tmpdir.path);
const proc = cp.fork(__filename, const proc = cp.fork(__filename,
[ 'child' ], { [ 'child' ], {
cwd: tmpdir.path,
execArgv: [ execArgv: [
'--no-warnings', '--no-warnings',
'--trace-event-categories', '--trace-event-categories',

View File

@ -3,22 +3,20 @@ const common = require('../common');
const assert = require('assert'); 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');
if (!common.isMainThread)
common.skip('process.chdir is not available in Workers');
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 FILE_NAME = 'node_trace.1.log';
const tmpdir = require('../common/tmpdir'); const tmpdir = require('../common/tmpdir');
tmpdir.refresh(); tmpdir.refresh();
process.chdir(tmpdir.path); const FILE_NAME = path.join(tmpdir.path, 'node_trace.1.log');
const proc = cp.spawn(process.execPath, const proc = cp.spawn(process.execPath,
[ '--trace-events-enabled', [ '--trace-events-enabled',
'--trace-event-categories', 'v8', '--trace-event-categories', 'v8',
'-e', CODE ]); '-e', CODE ],
{ cwd: tmpdir.path });
proc.once('exit', common.mustCall(() => { proc.once('exit', common.mustCall(() => {
assert(fs.existsSync(FILE_NAME)); assert(fs.existsSync(FILE_NAME));

View File

@ -2,13 +2,10 @@
const common = require('../common'); const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const cp = require('child_process'); const cp = require('child_process');
const path = require('path');
const fs = require('fs'); const fs = require('fs');
const path = require('path');
const tmpdir = require('../common/tmpdir'); const tmpdir = require('../common/tmpdir');
if (!common.isMainThread)
common.skip('process.chdir is not available in Workers');
const names = [ const names = [
'ContextifyScript::New', 'ContextifyScript::New',
'RunInThisContext', 'RunInThisContext',
@ -20,10 +17,10 @@ if (process.argv[2] === 'child') {
vm.runInNewContext('1 + 1'); vm.runInNewContext('1 + 1');
} else { } else {
tmpdir.refresh(); tmpdir.refresh();
process.chdir(tmpdir.path);
const proc = cp.fork(__filename, const proc = cp.fork(__filename,
[ 'child' ], { [ 'child' ], {
cwd: tmpdir.path,
execArgv: [ execArgv: [
'--trace-event-categories', '--trace-event-categories',
'node.vm.script' 'node.vm.script'