Skip to content

Commit a3c6a8d

Browse files
richardlaujasnell
authored andcommittedOct 21, 2018
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: #23698 Refs: #23674 (comment) Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent a5b1e7b commit a3c6a8d

15 files changed

+48
-84
lines changed
 

‎test/parallel/test-trace-events-all.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@ const common = require('../common');
33
const assert = require('assert');
44
const cp = require('child_process');
55
const fs = require('fs');
6-
7-
if (!common.isMainThread)
8-
common.skip('process.chdir is not available in Workers');
6+
const path = require('path');
97

108
const CODE =
119
'setTimeout(() => { for (var i = 0; i < 100000; i++) { "test" + i } }, 1)';
12-
const FILE_NAME = 'node_trace.1.log';
1310

1411
const tmpdir = require('../common/tmpdir');
1512
tmpdir.refresh();
16-
process.chdir(tmpdir.path);
13+
const FILE_NAME = path.join(tmpdir.path, 'node_trace.1.log');
1714

1815
const proc = cp.spawn(process.execPath,
19-
[ '--trace-events-enabled', '-e', CODE ]);
16+
[ '--trace-events-enabled', '-e', CODE ],
17+
{ cwd: tmpdir.path });
2018

2119
proc.once('exit', common.mustCall(() => {
2220
assert(fs.existsSync(FILE_NAME));

‎test/parallel/test-trace-events-api.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ const common = require('../common');
55

66
if (!process.binding('config').hasTracing)
77
common.skip('missing trace events');
8-
if (!common.isMainThread)
9-
common.skip('process.chdir is not available in Workers');
8+
common.skipIfWorker(); // https://github.com/nodejs/node/issues/22767
109

1110
const assert = require('assert');
1211
const cp = require('child_process');

‎test/parallel/test-trace-events-async-hooks.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,20 @@ const common = require('../common');
33
const assert = require('assert');
44
const cp = require('child_process');
55
const fs = require('fs');
6+
const path = require('path');
67
const util = require('util');
78

8-
if (!common.isMainThread)
9-
common.skip('process.chdir is not available in Workers');
10-
119
const CODE =
1210
'setTimeout(() => { for (var i = 0; i < 100000; i++) { "test" + i } }, 1)';
13-
const FILE_NAME = 'node_trace.1.log';
1411

1512
const tmpdir = require('../common/tmpdir');
1613
tmpdir.refresh();
17-
process.chdir(tmpdir.path);
14+
const FILE_NAME = path.join(tmpdir.path, 'node_trace.1.log');
1815

1916
const proc = cp.spawn(process.execPath,
2017
[ '--trace-event-categories', 'node.async_hooks',
21-
'-e', CODE ]);
18+
'-e', CODE ],
19+
{ cwd: tmpdir.path });
2220

2321
proc.once('exit', common.mustCall(() => {
2422
assert(fs.existsSync(FILE_NAME));

‎test/parallel/test-trace-events-binding.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ const common = require('../common');
33
const assert = require('assert');
44
const cp = require('child_process');
55
const fs = require('fs');
6-
7-
if (!common.isMainThread)
8-
common.skip('process.chdir is not available in Workers');
6+
const path = require('path');
97

108
const CODE = `
119
const { internalBinding } = require('internal/test/binding');
@@ -18,17 +16,17 @@ const CODE = `
1816
trace('b'.charCodeAt(0), 'missing',
1917
'type-value', 10, {'extra-value': 20 });
2018
`;
21-
const FILE_NAME = 'node_trace.1.log';
2219

2320
const tmpdir = require('../common/tmpdir');
2421
tmpdir.refresh();
25-
process.chdir(tmpdir.path);
22+
const FILE_NAME = path.join(tmpdir.path, 'node_trace.1.log');
2623

2724
const proc = cp.spawn(process.execPath,
2825
[ '--trace-event-categories', 'custom',
2926
'--no-warnings',
3027
'--expose-internals',
31-
'-e', CODE ]);
28+
'-e', CODE ],
29+
{ cwd: tmpdir.path });
3230

3331
proc.once('exit', common.mustCall(() => {
3432
assert(fs.existsSync(FILE_NAME));

‎test/parallel/test-trace-events-bootstrap.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22
const common = require('../common');
33
const assert = require('assert');
44
const cp = require('child_process');
5-
const path = require('path');
65
const fs = require('fs');
6+
const path = require('path');
77
const tmpdir = require('../common/tmpdir');
88

9-
if (!common.isMainThread)
10-
common.skip('process.chdir is not available in Workers');
11-
129
const names = [
1310
'environment',
1411
'nodeStart',
@@ -30,10 +27,10 @@ if (process.argv[2] === 'child') {
3027
1 + 1;
3128
} else {
3229
tmpdir.refresh();
33-
process.chdir(tmpdir.path);
3430

3531
const proc = cp.fork(__filename,
3632
[ 'child' ], {
33+
cwd: tmpdir.path,
3734
execArgv: [
3835
'--trace-event-categories',
3936
'node.bootstrap'

‎test/parallel/test-trace-events-category-used.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ const common = require('../common');
33
const assert = require('assert');
44
const cp = require('child_process');
55

6-
if (!common.isMainThread)
7-
common.skip('process.chdir is not available in Workers');
8-
96
const CODE = `
107
const { internalBinding } = require('internal/test/binding');
118
const { isTraceCategoryEnabled } = internalBinding('trace_events');
@@ -16,7 +13,6 @@ const CODE = `
1613

1714
const tmpdir = require('../common/tmpdir');
1815
tmpdir.refresh();
19-
process.chdir(tmpdir.path);
2016

2117
const procEnabled = cp.spawn(
2218
process.execPath,
@@ -25,7 +21,8 @@ const procEnabled = cp.spawn(
2521
// emits a warning.
2622
'--no-warnings',
2723
'--expose-internals',
28-
'-e', CODE ]
24+
'-e', CODE ],
25+
{ cwd: tmpdir.path }
2926
);
3027
let procEnabledOutput = '';
3128

@@ -42,7 +39,8 @@ const procDisabled = cp.spawn(
4239
// emits a warning.
4340
'--no-warnings',
4441
'--expose-internals',
45-
'-e', CODE ]
42+
'-e', CODE ],
43+
{ cwd: tmpdir.path }
4644
);
4745
let procDisabledOutput = '';
4846

‎test/parallel/test-trace-events-file-pattern.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@ const tmpdir = require('../common/tmpdir');
44
const assert = require('assert');
55
const cp = require('child_process');
66
const fs = require('fs');
7-
8-
if (!common.isMainThread)
9-
common.skip('process.chdir is not available in Workers');
7+
const path = require('path');
108

119
tmpdir.refresh();
12-
process.chdir(tmpdir.path);
1310

1411
const CODE =
1512
'setTimeout(() => { for (var i = 0; i < 100000; i++) { "test" + i } }, 1)';
@@ -20,10 +17,11 @@ const proc = cp.spawn(process.execPath, [
2017
// eslint-disable-next-line no-template-curly-in-string
2118
'${pid}-${rotation}-${pid}-${rotation}.tracing.log',
2219
'-e', CODE
23-
]);
20+
], { cwd: tmpdir.path });
2421

2522
proc.once('exit', common.mustCall(() => {
26-
const expectedFilename = `${proc.pid}-1-${proc.pid}-1.tracing.log`;
23+
const expectedFilename = path.join(tmpdir.path,
24+
`${proc.pid}-1-${proc.pid}-1.tracing.log`);
2725

2826
assert(fs.existsSync(expectedFilename));
2927
fs.readFile(expectedFilename, common.mustCall((err, data) => {

‎test/parallel/test-trace-events-fs-sync.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@ const common = require('../common');
33
const assert = require('assert');
44
const cp = require('child_process');
55
const fs = require('fs');
6+
const path = require('path');
67
const util = require('util');
78

8-
if (!common.isMainThread)
9-
common.skip('process.chdir is not available in Workers');
10-
119
const tests = new Array();
12-
const traceFile = 'node_trace.1.log';
1310

1411
let gid = 1;
1512
let uid = 1;
@@ -119,14 +116,14 @@ if (common.canCreateSymLink()) {
119116

120117
const tmpdir = require('../common/tmpdir');
121118
tmpdir.refresh();
122-
process.chdir(tmpdir.path);
119+
const traceFile = path.join(tmpdir.path, 'node_trace.1.log');
123120

124121
for (const tr in tests) {
125122
const proc = cp.spawnSync(process.execPath,
126123
[ '--trace-events-enabled',
127124
'--trace-event-categories', 'node.fs.sync',
128125
'-e', tests[tr] ],
129-
{ encoding: 'utf8' });
126+
{ cwd: tmpdir.path, encoding: 'utf8' });
130127
// Some AIX versions don't support futimes or utimes, so skip.
131128
if (common.isAIX && proc.status !== 0 && tr === 'fs.sync.futimes') {
132129
continue;

‎test/parallel/test-trace-events-metadata.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,21 @@ const common = require('../common');
33
const assert = require('assert');
44
const cp = require('child_process');
55
const fs = require('fs');
6-
7-
if (!common.isMainThread)
8-
common.skip('process.chdir is not available in Workers');
6+
const path = require('path');
97

108
const CODE =
119
'setTimeout(() => { for (var i = 0; i < 100000; i++) { "test" + i } }, 1);' +
1210
'process.title = "foo"';
13-
const FILE_NAME = 'node_trace.1.log';
1411

1512
const tmpdir = require('../common/tmpdir');
1613
tmpdir.refresh();
17-
process.chdir(tmpdir.path);
14+
const FILE_NAME = path.join(tmpdir.path, 'node_trace.1.log');
1815

1916
const proc = cp.spawn(process.execPath,
2017
[ '--trace-event-categories', 'node.perf.usertiming',
2118
'--title=bar',
22-
'-e', CODE ]);
19+
'-e', CODE ],
20+
{ cwd: tmpdir.path });
2321
proc.once('exit', common.mustCall(() => {
2422
assert(fs.existsSync(FILE_NAME));
2523
fs.readFile(FILE_NAME, common.mustCall((err, data) => {

‎test/parallel/test-trace-events-none.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,19 @@ const common = require('../common');
33
const assert = require('assert');
44
const cp = require('child_process');
55
const fs = require('fs');
6-
7-
if (!common.isMainThread)
8-
common.skip('process.chdir is not available in Workers');
6+
const path = require('path');
97

108
const CODE =
119
'setTimeout(() => { for (var i = 0; i < 100000; i++) { "test" + i } }, 1)';
12-
const FILE_NAME = 'node_trace.1.log';
1310

1411
const tmpdir = require('../common/tmpdir');
1512
tmpdir.refresh();
16-
process.chdir(tmpdir.path);
13+
const FILE_NAME = path.join(tmpdir.path, 'node_trace.1.log');
1714

1815
const proc_no_categories = cp.spawn(
1916
process.execPath,
20-
[ '--trace-event-categories', '""', '-e', CODE ]
17+
[ '--trace-event-categories', '""', '-e', CODE ],
18+
{ cwd: tmpdir.path }
2119
);
2220

2321
proc_no_categories.once('exit', common.mustCall(() => {

‎test/parallel/test-trace-events-perf.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22
const common = require('../common');
33
const assert = require('assert');
44
const cp = require('child_process');
5-
const path = require('path');
65
const fs = require('fs');
6+
const path = require('path');
77
const tmpdir = require('../common/tmpdir');
88

9-
if (!common.isMainThread)
10-
common.skip('process.chdir is not available in Workers');
11-
129
if (process.argv[2] === 'child') {
1310
const { performance } = require('perf_hooks');
1411

@@ -25,7 +22,6 @@ if (process.argv[2] === 'child') {
2522
ff(); // Will emit a timerify trace event
2623
} else {
2724
tmpdir.refresh();
28-
process.chdir(tmpdir.path);
2925

3026
const expectedMarks = ['A', 'B'];
3127
const expectedBegins = [
@@ -41,6 +37,7 @@ if (process.argv[2] === 'child') {
4137
[
4238
'child'
4339
], {
40+
cwd: tmpdir.path,
4441
execArgv: [
4542
'--trace-event-categories',
4643
'node.perf'

‎test/parallel/test-trace-events-process-exit.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,16 @@ const common = require('../common');
33
const assert = require('assert');
44
const cp = require('child_process');
55
const fs = require('fs');
6-
7-
if (!common.isMainThread)
8-
common.skip('process.chdir is not available in Workers');
6+
const path = require('path');
97

108
const tmpdir = require('../common/tmpdir');
11-
12-
const FILE_NAME = 'node_trace.1.log';
13-
149
tmpdir.refresh();
15-
process.chdir(tmpdir.path);
10+
const FILE_NAME = path.join(tmpdir.path, 'node_trace.1.log');
1611

1712
const proc = cp.spawn(process.execPath,
1813
[ '--trace-events-enabled',
19-
'-e', 'process.exit()' ]);
14+
'-e', 'process.exit()' ],
15+
{ cwd: tmpdir.path });
2016

2117
proc.once('exit', common.mustCall(() => {
2218
assert(fs.existsSync(FILE_NAME));

‎test/parallel/test-trace-events-promises.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22
const common = require('../common');
33
const assert = require('assert');
44
const cp = require('child_process');
5-
const path = require('path');
65
const fs = require('fs');
6+
const path = require('path');
77
const tmpdir = require('../common/tmpdir');
88

99
common.disableCrashOnUnhandledRejection();
1010

11-
if (!common.isMainThread)
12-
common.skip('process.chdir is not available in Workers');
13-
1411
if (process.argv[2] === 'child') {
1512
const p = Promise.reject(1); // Handled later
1613
Promise.reject(2); // Unhandled
@@ -19,10 +16,10 @@ if (process.argv[2] === 'child') {
1916
});
2017
} else {
2118
tmpdir.refresh();
22-
process.chdir(tmpdir.path);
2319

2420
const proc = cp.fork(__filename,
2521
[ 'child' ], {
22+
cwd: tmpdir.path,
2623
execArgv: [
2724
'--no-warnings',
2825
'--trace-event-categories',

‎test/parallel/test-trace-events-v8.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,20 @@ const common = require('../common');
33
const assert = require('assert');
44
const cp = require('child_process');
55
const fs = require('fs');
6-
7-
if (!common.isMainThread)
8-
common.skip('process.chdir is not available in Workers');
6+
const path = require('path');
97

108
const CODE =
119
'setTimeout(() => { for (var i = 0; i < 100000; i++) { "test" + i } }, 1)';
12-
const FILE_NAME = 'node_trace.1.log';
1310

1411
const tmpdir = require('../common/tmpdir');
1512
tmpdir.refresh();
16-
process.chdir(tmpdir.path);
13+
const FILE_NAME = path.join(tmpdir.path, 'node_trace.1.log');
1714

1815
const proc = cp.spawn(process.execPath,
1916
[ '--trace-events-enabled',
2017
'--trace-event-categories', 'v8',
21-
'-e', CODE ]);
18+
'-e', CODE ],
19+
{ cwd: tmpdir.path });
2220

2321
proc.once('exit', common.mustCall(() => {
2422
assert(fs.existsSync(FILE_NAME));

‎test/parallel/test-trace-events-vm.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22
const common = require('../common');
33
const assert = require('assert');
44
const cp = require('child_process');
5-
const path = require('path');
65
const fs = require('fs');
6+
const path = require('path');
77
const tmpdir = require('../common/tmpdir');
88

9-
if (!common.isMainThread)
10-
common.skip('process.chdir is not available in Workers');
11-
129
const names = [
1310
'ContextifyScript::New',
1411
'RunInThisContext',
@@ -20,10 +17,10 @@ if (process.argv[2] === 'child') {
2017
vm.runInNewContext('1 + 1');
2118
} else {
2219
tmpdir.refresh();
23-
process.chdir(tmpdir.path);
2420

2521
const proc = cp.fork(__filename,
2622
[ 'child' ], {
23+
cwd: tmpdir.path,
2724
execArgv: [
2825
'--trace-event-categories',
2926
'node.vm.script'

0 commit comments

Comments
 (0)
Please sign in to comment.