diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-02-08 19:13:35 +0100 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-02-11 19:57:21 +0100 |
commit | 902c71a9d09bce6b1da4258d1775375f6539bbec (patch) | |
tree | 8af3a58f990d2f64dd417b08ce743d7365ad6bc7 /test | |
parent | 5bc6e493c0642dd65e458026b8145f266d7d5417 (diff) | |
download | android-node-v8-902c71a9d09bce6b1da4258d1775375f6539bbec.tar.gz android-node-v8-902c71a9d09bce6b1da4258d1775375f6539bbec.tar.bz2 android-node-v8-902c71a9d09bce6b1da4258d1775375f6539bbec.zip |
test: add `Worker` + `--prof` regression test
Fixes: https://github.com/nodejs/node/issues/24016
PR-URL: https://github.com/nodejs/node/pull/26011
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-worker-prof.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/parallel/test-worker-prof.js b/test/parallel/test-worker-prof.js new file mode 100644 index 0000000000..5b0703f5f9 --- /dev/null +++ b/test/parallel/test-worker-prof.js @@ -0,0 +1,41 @@ +'use strict'; +const common = require('../common'); +const tmpdir = require('../common/tmpdir'); +const fs = require('fs'); +const assert = require('assert'); +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 + +if (process.argv[2] === 'child') { + const spin = ` + const start = Date.now(); + while (Date.now() - start < 200); + `; + new Worker(spin, { eval: true }); + eval(spin); + return; +} + +tmpdir.refresh(); +process.chdir(tmpdir.path); +spawnSync(process.execPath, ['--prof', __filename, 'child']); +const logfiles = fs.readdirSync('.').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 ticks = lines.filter((line) => /^tick,/.test(line)).length; + + // Test that at least 20 ticks have been recorded for both parent and child + // threads. When not tracking Worker threads, only 1 or 2 ticks would + // have been recorded. + // When running locally on x64 Linux, this number is usually at least 150 + // for both threads, so 15 seems like a very safe threshold. + assert(ticks >= 15, `${ticks} >= 15`); +} |