|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const common = require('../common'); |
| 4 | +if (!common.isLinux) { |
| 5 | + common.skip('thread names are read from /proc/self/task'); |
| 6 | +} |
| 7 | + |
| 8 | +const assert = require('assert'); |
| 9 | +const fs = require('fs'); |
| 10 | +const { spawnSync } = require('child_process'); |
| 11 | + |
| 12 | +function v8WorkerCount() { |
| 13 | + return fs.readdirSync('/proc/self/task').reduce((count, tid) => { |
| 14 | + try { |
| 15 | + const name = fs.readFileSync(`/proc/self/task/${tid}/comm`, 'utf8').trim(); |
| 16 | + return count + (name === 'node-V8Worker' ? 1 : 0); |
| 17 | + } catch { |
| 18 | + return count; |
| 19 | + } |
| 20 | + }, 0); |
| 21 | +} |
| 22 | + |
| 23 | +// The default --v8-pool-size is 1, and workers are created at platform init. |
| 24 | +assert.strictEqual(v8WorkerCount(), 1); |
| 25 | + |
| 26 | +const script = ` |
| 27 | + const fs = require('fs'); |
| 28 | + const n = fs.readdirSync('/proc/self/task').reduce((count, tid) => { |
| 29 | + try { |
| 30 | + const comm = '/proc/self/task/' + tid + '/comm'; |
| 31 | + const name = fs.readFileSync(comm, 'utf8').trim(); |
| 32 | + return count + (name === 'node-V8Worker' ? 1 : 0); |
| 33 | + } catch { |
| 34 | + return count; |
| 35 | + } |
| 36 | + }, 0); |
| 37 | + process.stdout.write(String(n)); |
| 38 | +`; |
| 39 | + |
| 40 | +const child = spawnSync(process.execPath, ['--v8-pool-size=4', '-e', script], { |
| 41 | + encoding: 'utf8', |
| 42 | +}); |
| 43 | +assert.ifError(child.error); |
| 44 | +assert.strictEqual(child.status, 0, child.stderr); |
| 45 | +assert.strictEqual(child.stdout, '4'); |
0 commit comments