summaryrefslogtreecommitdiff
path: root/test/parallel/test-trace-events-worker-metadata.js
blob: 4600ba3f7ec2fda0597948a5c14d2c19f8d7f083 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'use strict';
const common = require('../common');
const assert = require('assert');
const cp = require('child_process');
const fs = require('fs');
const { isMainThread } = require('worker_threads');

if (isMainThread) {
  const CODE = 'const { Worker } = require(\'worker_threads\'); ' +
               `new Worker('${__filename.replace(/\\/g, '/')}')`;
  const FILE_NAME = 'node_trace.1.log';
  const tmpdir = require('../common/tmpdir');
  tmpdir.refresh();
  process.chdir(tmpdir.path);

  const proc = cp.spawn(process.execPath,
                        [ '--trace-event-categories', 'node',
                          '-e', CODE ]);
  proc.once('exit', common.mustCall(() => {
    assert(fs.existsSync(FILE_NAME));
    fs.readFile(FILE_NAME, common.mustCall((err, data) => {
      const traces = JSON.parse(data.toString()).traceEvents;
      assert(traces.length > 0);
      assert(traces.some((trace) =>
        trace.cat === '__metadata' && trace.name === 'thread_name' &&
          trace.args.name === 'WorkerThread 1'));
    }));
  }));
} else {
  // Do nothing here.
}