Skip to content

Commit 8552bb4

Browse files
richardlauMylesBorins
authored andcommitted
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. Conflicts: test/parallel/test-trace-events-binding.js test/parallel/test-trace-events-category-used.js Backport-PR-URL: #23882 PR-URL: #23698 Refs: #23674 (comment) Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent d1102f8 commit 8552bb4

15 files changed

+48
-84
lines changed

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

Lines changed: 4 additions & 6 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 4 additions & 6 deletions
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

Lines changed: 4 additions & 6 deletions
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
process.binding("trace_events").emit(
@@ -21,15 +19,15 @@ const CODE = `
2119
'b'.charCodeAt(0), 'missing',
2220
'type-value', 10, 'extra-value', 20);
2321
`;
24-
const FILE_NAME = 'node_trace.1.log';
2522

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

3027
const proc = cp.spawn(process.execPath,
3128
[ '--trace-event-categories', 'custom',
32-
'-e', CODE ]);
29+
'-e', CODE ],
30+
{ cwd: tmpdir.path });
3331

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

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

Lines changed: 2 additions & 5 deletions
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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,17 @@ 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 = `console.log(
107
process.binding("trace_events").categoryGroupEnabled("custom")
118
);`;
129

1310
const tmpdir = require('../common/tmpdir');
1411
tmpdir.refresh();
15-
process.chdir(tmpdir.path);
1612

1713
const procEnabled = cp.spawn(
1814
process.execPath,
19-
[ '--trace-event-categories', 'custom', '-e', CODE ]
15+
[ '--trace-event-categories', 'custom', '-e', CODE ],
16+
{ cwd: tmpdir.path }
2017
);
2118
let procEnabledOutput = '';
2219

@@ -28,7 +25,8 @@ procEnabled.once('exit', common.mustCall(() => {
2825

2926
const procDisabled = cp.spawn(
3027
process.execPath,
31-
[ '--trace-event-categories', 'other', '-e', CODE ]
28+
[ '--trace-event-categories', 'other', '-e', CODE ],
29+
{ cwd: tmpdir.path }
3230
);
3331
let procDisabledOutput = '';
3432

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

Lines changed: 4 additions & 6 deletions
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

Lines changed: 3 additions & 6 deletions
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

Lines changed: 4 additions & 6 deletions
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

Lines changed: 4 additions & 6 deletions
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

Lines changed: 2 additions & 5 deletions
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

Lines changed: 4 additions & 8 deletions
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

Lines changed: 2 additions & 5 deletions
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

Lines changed: 4 additions & 6 deletions
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));

0 commit comments

Comments
 (0)