diff options
author | Richard Lau <riclau@uk.ibm.com> | 2019-03-05 08:56:16 -0500 |
---|---|---|
committer | Richard Lau <riclau@uk.ibm.com> | 2019-03-07 11:09:30 -0500 |
commit | 82a256ac6740b7a6d29439af911b86a7a0b2e63f (patch) | |
tree | ae632a3f24dbe190c152ab3be517b98ec15033ae /test/parallel/test-worker-prof.js | |
parent | 76e67e98843978223a74b177f4e53411caf95516 (diff) | |
download | android-node-v8-82a256ac6740b7a6d29439af911b86a7a0b2e63f.tar.gz android-node-v8-82a256ac6740b7a6d29439af911b86a7a0b2e63f.tar.bz2 android-node-v8-82a256ac6740b7a6d29439af911b86a7a0b2e63f.zip |
test: fix tests so they work in worker threads
Use the `cwd` option for child_process instead of `process.chdir()` to
allow tests to work with worker threads.
PR-URL: https://github.com/nodejs/node/pull/26453
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'test/parallel/test-worker-prof.js')
-rw-r--r-- | test/parallel/test-worker-prof.js | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/test/parallel/test-worker-prof.js b/test/parallel/test-worker-prof.js index d4344a8057..141b101a72 100644 --- a/test/parallel/test-worker-prof.js +++ b/test/parallel/test-worker-prof.js @@ -1,14 +1,12 @@ 'use strict'; -const common = require('../common'); +require('../common'); const tmpdir = require('../common/tmpdir'); const fs = require('fs'); const assert = require('assert'); +const { join } = require('path'); const { spawnSync } = require('child_process'); const { Worker } = require('worker_threads'); -if (!common.isMainThread) - common.skip('process.chdir is not available in Workers'); - // Test that --prof also tracks Worker threads. // Refs: https://github.com/nodejs/node/issues/24016 @@ -23,13 +21,14 @@ if (process.argv[2] === 'child') { } tmpdir.refresh(); -process.chdir(tmpdir.path); -spawnSync(process.execPath, ['--prof', __filename, 'child']); -const logfiles = fs.readdirSync('.').filter((name) => /\.log$/.test(name)); +spawnSync(process.execPath, ['--prof', __filename, 'child'], + { cwd: tmpdir.path }); +const files = fs.readdirSync(tmpdir.path); +const logfiles = files.filter((name) => /\.log$/.test(name)); assert.strictEqual(logfiles.length, 2); // Parent thread + child thread. for (const logfile of logfiles) { - const lines = fs.readFileSync(logfile, 'utf8').split('\n'); + const lines = fs.readFileSync(join(tmpdir.path, logfile), 'utf8').split('\n'); const ticks = lines.filter((line) => /^tick,/.test(line)).length; // Test that at least 15 ticks have been recorded for both parent and child |